In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].

If you are familiar with IRC chat, the support team is also reachable on PIRC network (`irc.pirc.pl`

) in `#szkopul`

channel. If you are not, just use email.

Please do not ask us things like "how to solve task XYZ?".

Please remember that the support team has to sleep sometimes or go to work in real life.

The most popular sport in Byteland is BitBall. Many cities of Byteland organize BitBall Leagues every year.
Each BitBall team has the right to participate in any number of leagues (no matter who is the organizer of the league).
At the end of the season all the results are summarized.
Each league publishes its own ranking list, which orders teams participating in that league. On the base of these ranking lists,
`The best BitBaller' magazine determines and publishes the super ranking list of **all** BitBall teams.

Determining the super ranking list is not an easy task. The process of calculating it requires the following assumptions. If a given team took -th place on the ranking list which consists of positions, then the number of points that this team scored is equal to . If the team did not participate in the league at all, it receives points. The distance between two given ranking lists is computed as follows: for each team we calculate the absolute value of the difference between the number of points the team scored on both lists, then we calculate the sum of such values obtained for all teams. Super ranking list that has to be determined is such that its total distance from all ranking lists is minimal.

Write a program which:

- reads from the standard input the description of the ranking lists for all BitBall leagues,
- determines the super ranking list for `The best BitBaller' magazine,
- writes total distance of the super ranking list to the standard output.

In the first line of the standard input there are two integers and (), separated by a single space. They represent the number of teams and the number of leagues. Following lines describe the leagues. Description of each league consists of an integer (), representing number of teams in the league, followed by numbers (). No two numbers and for are equal. Number means that -th place in the ranking list has been taken by the team . All numbers in the lines are separated by single spaces.

In the first line of the standard output your program should write a single integer - the total distance of the super ranking list (calculated as the sum of distances from all ranking lists).

For the input data:

4 2 3 1 2 3 2 4 3

the correct result is:

11

*Task author: Marcin Stefaniak.*