{Ilian Ivanov, C gr., MG'Baba Tonka'}
var
na4,a,b,br,n,i:integer;
flag,error:byte;
used,vh:array[1..2500]of integer;
begin
readln(n);
for i:=1 to 2000 do vh[i]:=0;
for i:=1 to 2000 do used[i]:=0;
for i:=1 to n do
    begin
    readln(a,b);
    used[a]:=1;
    used[b]:=1;
    inc(vh[b]);
    end;
    flag:=0;
    error:=0;
for i:=1 to 2000 do
    begin
    if used[i]=1
    then begin
         inc(br);
         if (vh[i]=0)and(flag=0)
         then begin flag:=1;na4:=i;end
         else if (vh[i]>1)or((vh[i]=0)and(flag=1))
              then error:=1;
         end;
    end;
if (flag=1)and(error=0)
then writeln(br,' ',na4)
else writeln('0 0');
end.


