Funny day in Playland

Little Arya wants a lot of fun, that’s why she is visiting Playland today. Playland is a very particular adventure park formed by N different attractions. Playland classifies its attractions in categories (roller coaster, terror, aquatic, extreme, ... ) and each attraction belongs at least one and at most two categories. Each Playland’s attraction works with a ticket system, if you want to use an attraction you must give a ticket from one of the categories this attraction belongs to, when you leave the attraction you will receive a ticket from other category the attraction belongs to (different from the one you gave when entering) or from the same category if the attraction belongs only to one. To begin the adventure Arya must choose one ticket that allows her entry in the attraction that she choose, after that she must follow the ticket exchange rule explained above. Arya is a girl with lot of energy and she wants to enjoy all the attractions of Playland but without repeating any (that would be consider boring and Arya just wanna have fun), but it is a very difficult choice. For example, suppose there are 4 attractions in Playland, numbered from 0 to 3. Attraction 0 belongs to the categories roller coaster and aquatic; attraction 1 belongs only to roller coaster, attraction 2 belongs to aquatic and extreme and attraction 3 belongs to terror and roller coaster. If Arya starts her adventure in the attraction 0 she can enter with the roller coaster or aquatic ticket and will receive the other when she leave the attraction. If she choose the roller coaster ticket then she will receive an aquatic ticket and only can entry in attraction 2, when she leaves attraction 2 she will receive an extreme ticket and can’t go to any other attraction. If she had chosen the aquatic ticket at the beginning she would receive a roller coaster ticket and then she could go to attraction 1 or 3. If she chooses attraction 3 when she leaves she will receive a terror ticket and again can’t go anywhere else. If she chooses attraction 1 she will receive a roller coaster ticket again when leaving and can only go to attraction 3 but she will never go to attraction 2 this way. It isn’t possible to visit all the attractions starting at attraction 0. However, it is possible to start in attraction 2 with a terror ticket, leaving with an aquatic ticket, then visit attraction 0 leaving with a roller coaster ticket, visit attraction 1 and leaving again with roller coaster ticket and, at last, visit attraction 3. As you can see, choose the attraction where the adventure must starts is not an easy choice, that’s why Arya needs your help to know if it is possible to choose an attraction to start such that she can visit all attractions from Playland only once. Can you help Arya? Input The input contains several test cases. The first line of a test case contains two integers N and C, separated by one space, denoting respectively the number of attractions (1 ≤ N ≤ 30000) and the number of categories in Playland (1 ≤ C ≤ 10000). Each of the next C lines describes a category. Every category starts with one integer K (0 ≤ K ≤ N) and then K integers representing the attractions who belongs to this category. All integers are separated by single spaces and the attractions are numbered from 0 to N − 1. Each attraction will appear at least once and at most twice and no attraction will be repeated on the same category. Output For each test case you have to print a single line, containing the integer ‘-1’ if it’s not possible to match the requirements or one integer representing the attraction where Arya can start her adventure. If there are multiple correct answers, print the smallest one.

2/2 Sample Input 44 13 3013 202 12 34 10 3012 11 12 34 11 210 202 12 Sample Output 2 -1 1