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