Organizing Cards 2

Given N boxes and M colors with per-box color counts, move individual cards so each color occupies exactly one box, minimizing total moves.

Hard8Dynamic programmingBit manipulationGreedyCombinatoricsNo attempts yetTime limit1sMemory limit512 MB

Problem

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 NN boxes. Cards are told apart by color, and there are MM colors. When the sorting is done, both of the following conditions must hold.

  1. Every box is empty, or holds cards of a single color only.
  2. 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.

Input

The first line contains the number of boxes NN and the number of card colors MM, separated by a space.

Each of the next NN lines describes the cards in one box. Each line holds MM integers, and the jj-th of them is the number of cards of color jj in that box.

Output

Print the minimum number of moves needed to satisfy both conditions on the first line.

Constraints

  • 1N501 \le N \le 50
  • 1M141 \le M \le 14
  • MNM \le N
  • The number of cards of one color in one box is an integer between 00 and 9999, inclusive.