eolymp
bolt
Try our new interface for solving problems

Bard

Every evening villagers in a small village gather around a bigfire and sing songs. A prominent member of the community is the bard. Every evening, if the bard is present, he sings a brand new song that no villager has heard before, and no other song is sung that night. In the event that the bard is not present, other villagers sing without him and exchange all songs that they know. Given the list of villagers present for \textbf{E} consecutive evenings, output all villagers that know all songs sung during that period. \InputFile The first line of input contains an integer \textbf{N}, \textbf{1} ≤ \textbf{N} ≤ \textbf{100}, the number of villagers. The villagers are numbered \textbf{1} to \textbf{N}. Villager number \textbf{1} is the bard. The second line contains an integer \textbf{E}, \textbf{1} ≤ \textbf{E} ≤ \textbf{50}, the number of evenings. The next \textbf{E} lines contain the list of villagers present on each of the \textbf{E} evenings. Each line begins with a positive integer \textbf{K}, \textbf{2} ≤ \textbf{K} ≤ \textbf{N}, the number of villagers present that evening, followed by \textbf{K} positive integers separated by spaces representing the villagers. No villager will appear twice in one night and the bard will appear at least once across all nights. \OutputFile Output all villagers that know all songs, including the bard, one integer per line in ascending order.
Time limit 1 second
Memory limit 64 MiB
Input example #1
5
7
3 1 2 4
3 3 4 5
4 1 2 3 4
4 1 3 4 5
2 3 4
4 2 3 4 5
3 1 3 5
Output example #1
1
3
5
Source Crimea 2010