var
a:array[0..1000000]of longint;
x1,y1,b,c,i,j,k,m,mm,n,x,y:longint;
begin
assign(input,'milk2.in');
assign(output,'milk2.out');
reset(input);
rewrite(output);
mm:=1000000;
readln(n);
for i:=1 to n do
begin
readln(c,b);
if b-1>m then m:=b-1;
if c<mm then mm:=c;
for j:=c to b-1 do
a[j]:=1;
end;
for i:=mm to m do
if a[i]=1 then
begin
x:=x+1;
if x>x1 then x1:=x;
y:=0;
end else
begin
y:=y+1;
if y>y1 then y1:=y;
x:=0;
end;
{if y1<>0 then y1:=y1+1;}
writeln(x1,' ',y1);
close(input);
close(output);
end.