{Tzolo Atanasov Tzolov 9v PMG Vasil Levski Smolian}
program tree;
type masiv1=array[1..2000] of 1..2000;
var mas,mas1:masiv1;
    dagi,j,z,i,a,b:1..2000;
    var f:boolean;
BEGIN
f:=true;
readln(dagi);
if dagi mod 2 =0 then begin writeln(0,' ',0);halt;end
   else begin
for i:= 1 to dagi do readln(mas[i],mas1[i]);
for i:= 1 to dagi do
    begin
    for j:= 1 to dagi do if mas[i]=mas1[j] then f:=false;
    if f=true then begin z:=mas[i];break;end;
    f:=true;
    end;
if f=false then begin writeln(0,' ',0);halt;end;
writeln(dagi+1,' ',z);
end;
END.
