QOJ.ac

QOJ

Süre Sınırı: 1 s Bellek Sınırı: 256 MB Toplam puan: 100 Hack'lenebilir ✓

#18966. 小礼品

İstatistikler

某学校集训队有 $2$ 位教练,共有 $n$ 支队伍,编号为 $1 \sim n$。今年有 $m$ 场 CCPC 区域赛,每支队伍最多参加 $2$ 站 CCPC 区域赛(可能有队伍参加 $0$ 站 CCPC 区域赛)。

每个赛站都会给每支参赛队伍的教练发放小礼品。不过,如果在同一个赛站中有多支参赛队伍的教练是相同的,那么该赛站只会给这位教练发放一个小礼品。

现在,每支队伍已经确定好要参加哪些赛站了,但是 CCPC 系统中还没有录入每支队伍的教练。在 CCPC 系统中,每支队伍只能指定 $1$ 位教练,并且一旦录入便无法改动。

请你合理地安排每支队伍的教练,使得这 $2$ 位教练拿到的小礼品总数最多。

Input

第一行输入两个整数 $n, m$ $(1 \le n, m \le 10^6)$,分别表示队伍数和赛站数。

接下来 $m$ 行,每行首先输入一个整数 $k$ $(0 \le k \le n)$,表示学校参加该赛站的队伍数;接下来输入 $k$ 个整数,表示参加该赛站的队伍编号,保证这 $k$ 个整数互不相同。

Output

输出一行一个整数,表示两位教练能拿到的小礼品总数的最大值。

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.