Taesu collects cards. He keeps them in boxes, and one box must hold cards of a single color only.
One day his younger brother took the cards out to play with them and put them back into arbitrary boxes. The rule Taesu set was not kept, so Taesu sorts the cards again from scratch.
There are N boxes. Cards are told apart by color, and there are M colors. When the sorting is done, both of the following conditions must hold.
- Every box is empty, or holds cards of a single color only.
- All cards of the same color are in the same box.
One move takes one card out of a box and puts it into another box. You are given how many cards of each color each box holds. Find the minimum number of moves needed to satisfy both conditions.