type vuzel=0..2000;
var r:array[vuzel,1..2]of vuzel;
n:vuzel;
b:boolean;
max:vuzel;
i:array[byte]of vuzel;
br:array[vuzel]of boolean;
begin
readln(n);
i[2]:=0;
for i[1]:=1 to 1000 do br[i[1]]:=true;
for i[1]:=1 to n do begin readln(r[i[1],1],r[i[1],2]);
                    if i[1]=1 then begin br[r[i[1],2]]:=false;  max:=r[i[1],1];
                    if r[i[1],2]>max then max:=r[1,2]; end
                    else begin if br[r[i[1],2]] then br[r[i[1],2]]:=false;
                    if r[i[1],1]>max then max:=r[i[1],2];
                    if r[i[1],2]>max then max:=r[i[1],2];
                    end; end;

begin
i[3]:=0;
for i[1]:=1 to max do if br[i[1]] then i[3]:=i[3]+1;
writeln(i[5],i[3]);
end;
end.