/*
排序,区间合并
*/
#include <iostream>
#include <fstream>
using namespace std;
struct ACT{
int begin;
int end;
}act[100000];
int cmp(const void *a,const void *b)
{
return ((struct ACT *)a)->begin-((struct ACT *)b)->begin;
}
int main()
{
ifstream cin;
ofstream cout;
cin.open("milk2.in");
cout.open("milk2.out");
int n,i;
cin>>n;
for ( i=0;i<n;i++)
cin>>act[i].begin>>act[i].end;
qsort(act,n,sizeof(act[0]),cmp);
int maxuse=act[0].end-act[0].begin;
int tmp=maxuse;
int maxrelax=0;
int tmprx=0;
struct ACT tar=act[0];
for ( i=1;i<n;i++)
{
if (act[i].begin<=tar.end)
{
if (act[i].end >tar.end)
tar.end=act[i].end;
tmp=tar.end-tar.begin;
}
else {
tmprx=act[i].begin-tar.end;
tar=act[i];
}
if (tmp>maxuse)
maxuse=tmp;
if (tmprx>maxrelax)
maxrelax=tmprx;
}
cout<<maxuse<<" "<<maxrelax<<endl;
return 0;
}