PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000019. Những người nghi nhiễm (The Suspects)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những người nghi nhiễm (The Suspects)

The Suspects

Source: POJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn students numbered from 00 to n−1n-1. Student 00 is known to be a suspect for an infectious disease. There are mm student groups. If any student in a group is a suspect, every other student in that group also becomes a suspect. This rule propagates through groups that share members.

Determine the total number of suspected students.

Input

The first line contains two integers n,mn,m. Each of the next mm lines describes one group: an integer kk giving its size, followed by the indices of its kk members.

Output

Print the number of suspected students, including student 00.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1501\le n\le 150; 0≤m≤100\le m\le 10; 0≤k≤n0\le k\le n; 0≤ai<n0\le a_i<n for every member; no duplicate student index within a group.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 0≤m≤700\le m\le 70; 0≤k≤n0\le k\le n; 0≤ai<n0\le a_i<n for every member; no duplicate student index within a group.
  • Subtask 3 (50 points): 1≤n≤300001\le n\le 30000; 0≤m≤5000\le m\le 500; 0≤k≤n0\le k\le n; 0≤ai<n0\le a_i<n for every member; no duplicate student index within a group.

Examples

Input

100 4
2 1 2
5 10 13 11 12 14
2 0 1
2 99 2

Output

4

Explanation

Student 0 shares a group with 1; 1 with 2; 2 with 99. Exactly {0,1,2,99} are suspected.