var
c,e,f,g,h,n,x,y:longint;
a,b:array[1..5000]of longint;
d:array[0..1000000]of longint;
begin
assign(input,'milk2.in');assign(output,'milk2.out');
reset(input);rewrite(output);
read(n);
for c:=1 to n do begin read(a[c],b[c]);
for e:=a[c]+1 to b[c] do d[e]:=1;end;x:=a[1];y:=b[1];
for c:=2 to n do begin if a[c]<x then x:=a[c];
if b[c]>y then y:=b[c];end;c:=x+1;
repeat e:=0;f:=0;while (c<=y)and(d[c]=1) do begin c:=c+1;e:=e+1;end;
if e>g then g:=e;while (c<=y)and(d[c]=0) do begin c:=c+1;f:=f+1;end;
if f>h then h:=f;until c=y+1;
write(g,' ',h);close(input);close(output);end.