Traveling Shoemaker

No attempts yetTime limit1sMemory limit128 MB

Problem

Once upon a time there was a very peaceful country named Nlogonia. Back then, Poly the Shoemaker could travel freely from city to city doing his job without any trouble. The task was easy, because every city in Nlogonia had a direct road to every other city. He could visit each city exactly once and fix everybody's shoes.

But not anymore. War has come to Nlogonia, and the age of free travel is over.

Confederations, each identified by a color, have formed among the cities. Every city now belongs to at least one and at most two confederations. To enter a city you must hand the border officer a ticket from one of the confederations that city belongs to. When you leave, you receive a ticket from the other confederation the city belongs to (different from the one you handed over) — or from the same confederation if the city belongs to only one.

Poly is an old friend of Nlogonia, so he is allowed to pick both the ticket and the first city he enters. After that, he must obey the rules above. He still wants to visit each city exactly once, and he may choose where to begin.

For example, suppose there are four cities labeled $0$ to $3$. City $0$ belongs to red and green; city $1$ belongs only to red; city $2$ belongs to green and yellow; and city $3$ belongs to blue and red. If Poly starts at city $0$, he enters carrying either the red or the green ticket and leaves with the other. If he enters with red he leaves with green, and then the only city he can move to is city $2$; leaving city $2$ he receives yellow and is stuck. If he enters city $0$ with green he leaves with red, and can then move to city $1$ or city $3$. Choosing city $3$, he leaves with blue and is stuck. Choosing city $1$, he leaves with red again (city $1$ belongs only to red) and can only reach city $3$, never city $2$. So it is impossible to visit every city exactly once when starting at city $0$. It is possible, however, to start at city $2$ with the yellow ticket, leave with green, visit city $0$, leave with red, visit city $1$, leave with red again, and finally visit city $3$.

Help Poly decide whether he can choose a starting city from which he can visit all cities of Nlogonia exactly once.

Input

The input contains several test cases. The first line of each test case has two integers $N$ and $C$ ($1 \le N \le 500$ and $1 \le C \le 100$), the number of cities and the number of confederations. Each of the next $C$ lines describes one confederation: it starts with an integer $K$ ($0 \le K \le N$) followed by $K$ integers, the cities that belong to that confederation. Cities are numbered from $0$ to $N-1$. Every city appears in at least one and at most two confederations, and no city is repeated within the same confederation. All integers on a line are separated by single spaces.

The end of the input is indicated by a line containing two zeroes (0 0).

Output

For each test case, print a single line. Print $-1$ if Poly cannot complete the tour under the rules; otherwise print the number of a city from which he can start and visit every city exactly once. If several cities work, print the smallest one.