#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1000010
using namespace std;
int n,s1=999999999,s2,ans1,ans2,sum1,sum2;
int begin,end,a[N];
int read()
{
int x=0,f=1; char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘) f=-1; ch=getchar();}
while(ch<=‘9‘&&ch>=‘0‘){x=x*10+ch-‘0‘; ch=getchar();}
return x*f;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
begin=read(),end=read();
for(int j=begin;j<end;j++)
a[j]=1;
s1=min(s1,begin);
s2=max(s2,end);
}
for(int i=s1;i<=s2;i++)
{
if(a[i]==1)
{
ans2=max(ans2,sum2);
sum2=0;
sum1++;
}
else
{
ans1=max(ans1,sum1);
sum1=0;
sum2++;
}
}
printf("%d %d",ans1,ans2);
return 0;
}