var n,i,nv,kv,koren,g,j,brvazli,v:integer;
    ot:byte;
    dag:array[1..2000,1..2] of integer;
    vazli:array[1..2000]of byte;
begin
     readln(n);

     for i:=1 to n do
          readln(dag[i,1],dag[i,2]);

     i:=0;
     koren:=0;
     repeat
           i:=i+1;
           nv:=dag[i,1];
           kv:=dag[i,2];
           g:=0;
           repeat
                 g:=g+1;
                if dag[g,1]=kv then
                begin
                     ot:=1;
                     j:=0;
                     repeat
                           j:=j+1;
                         if dag[j,2]=nv then ot:=0;
                     until(j=n)
                end;
           until(g=n);
           if koren<>0 then koren:=-5  ;
           if (ot=1) and (koren=0) then koren:=dag[i,1];
     until(i=n)or(koren=-5);

     brvazli:=0;
     for i:=1 to n do
         for j:=1 to 2 do
         begin
             v:=dag[i,j];
             if vazli[v]<>31 then
             begin
                  brvazli:=brvazli+1;
                  vazli[v]:=31;
             end;
         end;

     if (koren>0) then writeln(brvazli,' ',koren)
        else writeln('0 0');
end.