#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll N=1E5+7;
const ll INF =1e9+7;

ll l[N],r[N];
struct stu{
    ll a,b;
    bool friend operator < (const stu &x,const stu &y) {
        return x.a>y.a;
    }
}s[N];
ll arr[N];
int main(){
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>l[i]>>r[i];
    ll ans1=0;
    ll maxlen=0;
    ll minnr=INF,p;
    ll maxxl=0,q;

    for(ll i=1;i<=n;i++){
        if(l[i]>maxxl) {
            maxxl=l[i];
            p=i;
        }
        if(r[i]<minnr){
            minnr=r[i];
            q=i;
        }
        maxlen=max(maxlen,r[i]-l[i]+1);
    }
    ans1+=maxlen;
    if(minnr>maxxl) ans1+=minnr-maxxl+1;
    for(ll i=1;i<=n;i++){
        s[i].a=max(r[i]-maxxl+1,(ll)0);
        s[i].b=max(minnr-l[i]+1,(ll)0);
    }
    sort(s+1,s+1+n);
    arr[n+1]=INF;
    for(ll i=n;i>=1;i--)  arr[i]=min(arr[i+1],s[i].b);
    ll ans2=0;
    for(ll i=1;i<n;i++) {
        ans2=max(ans2,s[i].a+arr[i+1]);
    }
//    cout<<ans2<<"   "<<ans1<<endl;
    cout<<max(ans2,ans1)<<endl;
    return 0;
}
