$Alice$ is a well-known builder who has designed many well-known buildings, such as the rainbow tower. This time, someone asks her to build a strange building, which only needs stones. So $Alice$ bought a batch of stones. Now, there are n heaps of stones in front of $Alice$. $Alice$ can start work only after she combines these n heaps of stones into a heap. $ Alice$ has prepared a machine to merge the stones. However, there is something wrong with this machine. It takes at least two heaps at a time and at most $m$ heaps of stones to merge. The cost of each merging is the number of stones. Alice wants to know the minimum cost of merging $n$ heaps of stones into one heap of stones.