program xxxx;
var i,j,n,x,y,v,w,c,b,max,min:longint;
a:array[-2..1000000] of boolean;
begin
min:=1000000;
assign(input,'milk2.in');
reset(input);
assign(output,'milk2.out');
rewrite(output);
read(n);
for i:=1 to n do
begin
read(c,b);
if b>max then
max:=b;
if c<min then
min:=c;
for j:=c+1 to b do
a[j]:=true;
end;
for i:=-2 to max do
if a[i]<>true then
a[i]:=false;
for i:=min+1 to max do
begin
if a[i]=true then
inc(x)
else
inc(y);
if (a[i+1]=false)and(a[i]=true) then
begin
if x>v then
v:=x;
x:=0;
end;
if (a[i+1]=true)and(a[i]=false) then
begin
if y>w then
w:=y;
y:=0;
end;
end;
write(v,' ',w);
close(input);
close(output);
end.