The Byteland Security Agency (BSA) employs two kinds of workers: commanders and clerks. Every worker is identified by a number. For each clerk, the archive keeps the clerk's own signature together with the signatures of the workers (clerks or commanders) who vouch for that clerk's loyalty. Every clerk must be vouched for by at least one worker, and over time more guarantors may be added. A commander is a worker whom nobody vouches for.
BSA has discovered that a spy from hostile Microsoftland has slipped into the ranks of the commanders. Afterwards, more spies were hired into clerk positions, each vouched for only by workers who are themselves spies (the spy-commander and/or other spies already hired). In other words, the guarantors of a spy clerk are exclusively spies.
A clerk's reliability is questioned when the clerk has not obtained a guarantee, directly or indirectly, from any commander who is not a spy. Formally, the clerk is questioned when there is no sequence of workers p1,p2,…,pk such that p1 is a commander who is not a spy, pk is that clerk, and pi vouches for pi+1 for every i=1,…,k−1.
A clerk is suspected of spying if assuming some one commander to be a spy causes that clerk's reliability, which was not in question beforehand, to become questioned. The BSA command wants the complete list of such clerks.
Write a program that reads the number of workers and the guarantee information, determines the clerks suspected of spying, and writes them to standard output.
The first line contains one integer n (1≤n≤500), the number of BSA workers. The workers are numbered from 1 to n.
Each of the next n lines describes the guarantees for one worker: line i+1 (for i=1,…,n) describes worker i. The line begins with an integer mi (mi≥0), the number of guarantees worker i has received, followed by mi integers giving the numbers of the workers who vouch for worker i. All numbers on a line are separated by single spaces, so the line holds mi+1 integers in total.
A worker whom nobody vouches for (that is, mi=0) is a commander; every other worker is a clerk.
If at least one clerk is suspected of spying, print their numbers in increasing order, one per line.
If no clerk is suspected, print a single line containing the word BRAK.
Suppose the commanders are Alice and Gregor, and the clerks are vouched for as follows:
Bob, Charlie, and David can be reached only from Alice, so assuming Alice is a spy makes them questioned. Henry and Isabelle can be reached only from Gregor, so assuming Gregor is a spy makes them questioned. Eve and Frank can be reached from both commanders, so no single spy assumption questions them. The clerks suspected of spying are therefore Bob, Charlie, David, Henry, and Isabelle.