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.
The input contains several test cases. Each test case begins with a line holding two integers n and m, where n is the number of students and m is the number of groups, with 0<n≤30000 and 0≤m≤500. Every student has a distinct number between 0 and n−1, and in every test case student 0 is a suspect from the start. That line is followed by the member lists of the m groups, one line per group. Each line begins with an integer k, the number of members in the group, followed by the numbers of the k students in that group. The integers on a line are separated by at least one space.
A test case with n=0 and m=0 marks the end of the input and is not processed.
For each test case, print the number of suspects on one line.