program ex;
var
a:array[0..5001] of boolean;
j,wei,n,y,x,x1,y1,i:longint;
f:text;
begin
assign(f,'milk2.in');
reset(f);
for i:=0 to 5001 do
a[i]:=false;
wei:=0;
readln(f,n);
for i:=1 to n do
begin
readln(f,x,y);
if y>wei then
wei:=y;
for j:=x+1 to y do
a[j]:=true;
end;
close(f);
x:=0;y:=0;x1:=0;y1:=0;
for i:=1 to wei-1 do
begin
if (a[i]=true) then
inc(x)
else
if (x>x1) then
x1:=x
else
x:=0;
if (a[i]=false) then
inc(y)
else
if (y>y1) then
y1:=y
else
y:=0;
end;
if x>x1 then
x1:=x;
if y>y1 then
y1:=y;
assign(f,'milk2.out');
rewrite(f);
writeln(f,x1,' ',y1);
close(f);
end.