Time limit
2s
Memory limit
128 MB
Taesu collects cards and stores them in boxes. One day, his younger sibling played with the cards and put them back into the boxes without following Taesu's ordering rule, so Taesu wants to organize them again.
There are N boxes and M different card colors. Taesu wants the boxes to satisfy these conditions:
For each box, you are given how many cards of each color it contains. Find the minimum number of moves needed to satisfy the conditions. One move means taking one or more cards from one box and putting them into another box; the cards taken in a single move do not have to be the same color.
The first line contains the number of boxes N and the number of card colors M.
Each of the next N lines contains information about one box. Each line has M integers: the number of cards of color 1, color 2, ..., color M, in that order.
Print the minimum number of moves needed to make the boxes satisfy the conditions.
1 <= N, M <= 50