Var A1:Array[0..2000]of Word;A2,A3:Array[0..2000]of Boolean;A4,A5,A6:Word;B1,B2:Word;B3,B4:Word;B5:Boolean;Begin ReadLn(A4);B5
:=True;For A5:=1to A4 do Begin ReadLn(B1,B2);If A1[B2]=0then Begin A1[B2]:=B1;If A2[B1]=False then Begin A2[B1]:=True;Inc(B3);
end;If A2[B2]=False then Begin A2[B2]:=True;Inc(B3);end;end else B5:=False;end;If B5 then Begin B4:=0;For A5:=0to A4 do If(A1[
A5]=0)and(A2[A5]=True)then If B4=0then B4:=A5 else Begin B5 := False;Break;end;end;If B5 then Begin For A5:=0 to A4 do If A2[A5
]and(A5 <> B4) then Begin A6:=A5;If A3[A5] then A6:=0 else Repeat A3[A6]:=True;A6:=A1[A6];Until(A6=B4)or(A6=A5);If(A6=A5)and(A6
<> B4)then Begin B5:=False;Break;end;end;end;If B5 then WriteLn(B3,' ',B4)else WriteLn('0 0');end.