type
 yey=integer;
var
 a:array [1..2000] of yey; {roditeli}
 u:array [1..2000] of boolean; {used}
 up:array [1..2000] of yey; {used points}
 upc:yey; {upc=br - nz 6to taka go napraih}
 n,bv,kor:yey; {broi vuzli; koren}
 i,j,k,l:integer;
 fl:boolean;
begin
  for j:=1 to 2000 do
   a[j]:=2001;
  readln (n);
  fl:=true; bv:=0;
  for i:=1 to n do
   begin
     readln (k,l);
     if a[l]=2001 then
      a[l]:=k
     else
      fl:=false;
     if not u[k] then begin
	   inc(bv); u[k]:=true; inc(upc); up[upc]:=k; end;
     if not u[l] then begin
	   inc(bv); u[l]:=true; inc(upc); up[upc]:=l; end;
   end;

  kor:=2001;
  for i:=1 to upc do
   begin
     if a[up[i]]=2001 then
      if kor=2001 then kor:=up[i]
      else begin fl:=false; break; end;
   end;

  if (not fl)or(kor=2001) then
   begin
     bv:=0; kor:=0;
   end;

  writeln (bv,' ',kor);
end.