Football
Football has always been a beloved sport in Georgia. During the Soviet era, Tbilisi's "Dynamo" won the UEFA Cup Winners' Cup, earning Georgian footballers the nickname "Soviet Brazilians." This was due not only to their skill but also because, like in Brazil, nearly everyone in Georgia played football at an amateur level. Numerous amateur tournaments took place, and teams often participated in multiple tournaments simultaneously.
In one Georgian city, officials decided to rank the local football teams. To achieve this, they collected the final standings from all the city's tournaments at the end of the season and applied the following scoring system: if a team finishes in the m-th place in a tournament with l participants, it earns l+1-m local points. If a team did not participate in a tournament, it receives 0 local points. The distance between two tournament tables is defined as the sum of the absolute differences in local points scored by each team in these tables. The goal is to create an overall ranking list that has the smallest total distance to all the tournament tables.
Your task is to construct this overall ranking list based on the final tables of all tournaments held in the city and calculate its total distance from these tables.
Input
The first line contains two integers n and k (2 ≤ n ≤ 500, 1 ≤ k ≤ 500), representing the number of teams in the city and the number of tournaments played. The next k lines describe the final tables of the tournaments. Each table i begins with an integer m_i (2 ≤ m_i ≤ n), indicating the number of teams in the i-th tournament, followed by a list of m_i teams in order of their ranking, starting from the first place (each team is identified by an integer from 1 to n). No two teams share a position in any table.
Output
Output a single integer p, which is the total distance of the constructed overall ranking list from all the final tables of the tournaments provided in the input.