#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,m,i,j,pl[100005],pr[100005],sl[100005],sr[100005],ans;
struct rg{
	int l,r;
}a[100005];
bool cmp(rg x,rg y)
{
	return x.l<y.l;
}
int main(){
	cin>>n;
	rep(i,n){
		cin>>a[i].l>>a[i].r;
	}
	sort(a+1,a+n+1,cmp);
	pl[1]=a[1].l;pr[1]=a[1].r;
	for(i=2;i<=n;i++){
		pl[i]=max(a[i].l,pl[i-1]);
		pr[i]=min(a[i].r,pr[i-1]);
	}
	sl[n]=a[n].l;sr[n]=a[n].r;
	for(i=n-1;i;i--){
		sl[i]=max(a[i].l,sl[i+1]);
		sr[i]=min(a[i].r,sr[i+1]);
	}
	pr[0]=sr[n+1]=0x3f3f3f3f;
	rep(i,n){
		ans=max(ans,(a[i].r-a[i].l+1)+max(0,min(pr[i-1],sr[i+1])-max(pl[i-1],sl[i+1])+1));
	}
	rep(i,n-1){
		ans=max(ans,max(0,pr[i]-pl[i]+1)+max(0,sr[i+1]-sl[i+1]+1));
	}
	cout<<ans<<endl;
	return 0;
}