Signatures

No attempts yetTime limit3sMemory limit512 MB

Problem

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,,pkp_1, p_2, \ldots, p_k such that p1p_1 is a commander who is not a spy, pkp_k is that clerk, and pip_i vouches for pi+1p_{i+1} for every i=1,,k1i = 1, \ldots, 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.

Input

The first line contains one integer nn (1n5001 \le n \le 500), the number of BSA workers. The workers are numbered from 11 to nn.

Each of the next nn lines describes the guarantees for one worker: line i+1i+1 (for i=1,,ni = 1, \ldots, n) describes worker ii. The line begins with an integer mim_i (mi0m_i \ge 0), the number of guarantees worker ii has received, followed by mim_i integers giving the numbers of the workers who vouch for worker ii. All numbers on a line are separated by single spaces, so the line holds mi+1m_i + 1 integers in total.

A worker whom nobody vouches for (that is, mi=0m_i = 0) is a commander; every other worker is a clerk.

Output

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.

Hint

Suppose the commanders are Alice and Gregor, and the clerks are vouched for as follows:

  • Bob is vouched for by Alice.
  • Charlie is vouched for by Bob.
  • David is vouched for by Bob and by Charlie.
  • Eve is vouched for by Alice and Gregor.
  • Frank is vouched for by Eve.
  • Henry is vouched for by Gregor and Isabelle.
  • Isabelle is vouched for by Gregor and Henry.

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.