The Suspects

No attempts yetTime limit1sMemory limit128 MB

Problem

Severe acute respiratory syndrome (SARS) is an atypical pneumonia of unknown cause, and it was recognized as a global threat in mid-March 2003. To keep transmission as low as possible, the best strategy is to separate the suspects from everyone else.

At Not-Spreading-Your-Sickness University (NSYSU) there are many student groups. Students in the same group talk to each other often, and one student may join several groups. To stop SARS from spreading, NSYSU collected the member lists of all student groups and added the following rule to its standard operating procedure.

Once one member of a group is a suspect, every member of that group is a suspect.

Working out the full set of suspects by hand after a single student is flagged turns out to be hard. Write a program that finds all of them.

Input

The input contains several test cases. Each test case begins with a line holding two integers nn and mm, where nn is the number of students and mm is the number of groups, with 0<n300000 < n \le 30000 and 0m5000 \le m \le 500. Every student has a distinct number between 00 and n1n-1, and in every test case student 00 is a suspect from the start. That line is followed by the member lists of the mm groups, one line per group. Each line begins with an integer kk, the number of members in the group, followed by the numbers of the kk students in that group. The integers on a line are separated by at least one space.

A test case with n=0n = 0 and m=0m = 0 marks the end of the input and is not processed.

Output

For each test case, print the number of suspects on one line.