type tr=array[1..2] of integer;
type tree=array[1..2000] of tr;
var
 a:tree;
 n,p:integer;
procedure inp;
 var
  i:integer;
 begin
  readln(n);
  for i:=1 to n do readln(a[i][1],a[i][2]);
 end;
function test:boolean;
 var
  b:boolean;
  i,j:integer;
 begin
  b:=true;
  for i:=1 to n do for j:=i+1 to n do if a[i][2]=a[j][2] then b:=false;
  test:=b;
 end;
function findk:integer;
 var
  i,j,l,m,h:integer;
 begin
  l:=0;
  m:=0;
  for i:=1 to n do begin
                    for j:=1 to n do if a[i][1]=a[j][2] then m:=m+1;
                    if (m=0)and(h<>a[i][1]) then begin
                                                  l:=l+1;
                                                  h:=a[i][1];
                                                 end;
                    m:=0;
                   end;
  if l=1 then findk:=h
          else findk:=0;
 end;
function num:integer;
 var
  i,j,l:integer;
 begin
  l:=0;
  for i:=1 to n do begin
                    for j:=i+1 to n do if a[i][1]=a[j][1] then a[j][1]:=0;
                    for j:=1 to n do if a[i][1]=a[j][2] then a[j][2]:=0;
                   end;
  for i:=1 to n do begin
                    if a[i][1]<>0 then l:=l+1;
                    if a[i][2]<>0 then l:=l+1;
                   end;
  num:=l;
 end;
begin
 inp;
 if test=true then begin
                    p:=findk;
                    if p<>0 then writeln(num,' ',p);

                   end;
end.