var n:longint;
    kor,br,brk:longint;
    i:integer;
    x,y:longint;
    nt:boolean;
    max:longint;
    a,b:array[1..2000]of integer;
    k:array[1..2000]of boolean;
 begin
  nt:=true;
  readln(n);
  max:=-maxlongint;
  for i:=1 to n do
   begin
    readln(x,y);
    if max<x then max:=x;
    if (a[x]=0)and(b[x]=0) then inc(br);
    if b[y]=1 then nt:=false;
    if (b[y]=0)and(a[y]=0) then inc(br);
    k[y]:=true;
    inc(a[x]);
    inc(b[y]);
   end;
  for i:=1 to max do
   if (a[i]>0)or(b[i]>0) then
    if k[i]=false then
     begin
      inc(brk);
      if brk=2 then begin writeln('0 0');exit;end;
      kor:=i;
     end;
 if brk<>1 then nt:=false;
  if nt then writeln(br,' ',kor)
  else       writeln('0 0');
 end.