QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#18966. Small Gift

统计

There are $2$ coaches in the school training team, and there are $n$ teams in total, numbered $1 \sim n$. This year there are $m$ CCPC regional contests, and each team can participate in at most $2$ CCPC regionals (some teams may participate in $0$ CCPC regionals).

Each contest site gives a gift to the coach of each participating team. However, if at the same site several participating teams have the same coach, that site gives only one gift to that coach.

Now, each team has already decided which contest sites it will participate in, but the coaches have not yet been entered into the CCPC system. In the CCPC system, each team can only be assigned $1$ coach, and once entered, it cannot be changed.

Please assign a coach to each team reasonably, so that the total number of gifts received by these $2$ coaches is maximized.

Input

The first line contains two integers $n, m$ $(1 \le n, m \le 10^6)$, representing the number of teams and the number of contest sites.

In the next $m$ lines, each line first contains an integer $k$ $(0 \le k \le n)$, representing the number of teams from the school participating in that site; then it contains $k$ integers representing the team numbers participating in that site. It is guaranteed that these $k$ integers are pairwise distinct.

Output

Output a single integer, the maximum total number of gifts the two coaches can receive.

Examples

Input 1

3 3
2 1 2
2 1 3
2 2 3

Output 1

5

Input 2

3 3
2 1 3
2 2 3
0

Output 2

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.