/*
ID:zengzha
LANG:C++
TASK:milk2
*/
#include<stdio.h>
int a[1000010],s=1000000,t,u,v,p,q;
int main(){
int i,j,n,x,y;
freopen("milk2.in","r",stdin);
freopen("milk2.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d%d",&x,&y);
if(s>x)s=x;
if(t<y)t=y;
for(j=x+1;j<=y;j++)a[j]=1;
}for(i=s+1;i<=t;i++){
if(a[i]){
if(q<v)q=v;
u++;v=0;
}else{
if(p<u)p=u;
v++;u=0;
}
}
if(p<u)p=u;
if(q<v)q=v;
printf("%d %d\n",p,q);
return 0;
}
ID:zengzha
LANG:C++
TASK:milk2
*/
#include<stdio.h>
int a[1000010],s=1000000,t,u,v,p,q;
int main(){
int i,j,n,x,y;
freopen("milk2.in","r",stdin);
freopen("milk2.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d%d",&x,&y);
if(s>x)s=x;
if(t<y)t=y;
for(j=x+1;j<=y;j++)a[j]=1;
}for(i=s+1;i<=t;i++){
if(a[i]){
if(q<v)q=v;
u++;v=0;
}else{
if(p<u)p=u;
v++;u=0;
}
}
if(p<u)p=u;
if(q<v)q=v;
printf("%d %d\n",p,q);
return 0;
}