type
 bchr=array[1..2000] of boolean;
 artree=array[1..2000] of bchr;
 rez=array[1..2000] of integer;

var
 tree:artree;
 n:Integer;
 res:rez;

procedure inittree(var tree:artree;n:Integer);
var i,j:Integer;
begin
 for i:=1 to n do for j:=1 to n do tree[i][j]:=false;
end;

procedure readtree(var tree:artree;n:Integer;var res:rez);
var
 i,a,b,c:Integer;
begin
 for i:=1 to n do res[i]:=0;
 c:=1;
 for i:=1 to n do
 begin
  readln(a,b);
  tree[a][b]:=true;
  res[c]:=a;
  res[c+1]:=b;
  c:=c+2;
 end;
end;

procedure istree(tree:artree;n:Integer);
begin
end;

procedure showkloni(res:rez;n:integer);
var i,j,cnt:Integer;
begin
 cnt:=0;
 for i:=1 to n*2 do
 begin
  for j:=1 to n*2 do
  begin
   if (i<>j) and (res[i]=res[j]) then res[j]:=0;
  end;
 end;
 for i:=1 to n*2 do
 begin
  if res[i]<>0 then inc(cnt);
 end;
 write(cnt,' ');
end;

function rootis(res:rez;tree:artree;n:integer):integer;
var
 i,j,cnt:Integer;
 dqsno,lqvo:rez;
begin
 cnt:=1;
 for i:=1 to n*2 do
 begin
  for j:=1 to n*2 do
  begin
   if tree[i][j]=true then
   begin
    dqsno[cnt]:=j;
    inc(cnt);
   end;
  end;
 end;
 {------------------}
 cnt:=1;
 for i:=1 to n*2 do
 begin
  for j:=1 to n*2 do
  begin
   if tree[i][j]=true then
   begin
    lqvo[cnt]:=i;
    inc(cnt);
   end;
  end;
 end;
 {-----------------}
 for i:=1 to n do
 begin
  cnt:=i;
  for j:=1 to n do
  begin
   if lqvo[i]=dqsno[j] then cnt:=0;
  end;
  if cnt=i then break;
 end;
 rootis:=cnt;
end;

begin
 readln(n);
 inittree(tree,n);
 readtree(tree,n,res);
 showkloni(res,n);
 writeln(rootis(res,tree,n));
end.
