///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int n,l[M],r[M];
vector<pair<pi,int>>vec,v;
bool cmp(pair<pi,int>x,pair<pi,int>y)
{
    int l1=x.fi.fi;
    int r1=x.fi.si;
    int l2=y.fi.fi;
    int r2=y.fi.si;
    if(l1!=l2)
    {
        return l1>l2;
    }
    return r1>r2;
}
bool cmp2(pair<pi,int>x,pair<pi,int>y)
{
    int l1=x.fi.fi;
    int r1=x.fi.si;
    int l2=y.fi.fi;
    int r2=y.fi.si;
    if(r1!=r2)
    {
        return r1<r2;
    }
    return l1<l2;
}

int fnd(int x,int y)
{
    int ret=x-y+1;
    ret=max(ret,0LL);
    return ret;
}
 main()

{
    fast
    cin>>n;
    set<pi>lft,rgt;
    f(i,1,n)
    {
        cin>>l[i]>>r[i];
        vec.pb(mp(mp(l[i],r[i]),i));
        lft.insert(mp(l[i],i));
        rgt.insert(mp(r[i],i));
    }
    int ses=0;
    for(int i=1;i<=n;i++)
    {
        int L=l[i];
        int R=r[i];
        int cost=fnd(R,L);
        lft.erase(mp(L,i));
        rgt.erase(mp(R,i));
        int mL=lft.rbegin()->fi;
        int mR=rgt.begin()->fi;
        cost+=fnd(mR,mL);
        ses=max(ses,cost);
        lft.insert(mp(L,i));
        rgt.insert(mp(R,i));
    }
    //cout<<ses<<endl;
    sort(vec.begin(),vec.end(),cmp);
    pi st=vec[0].fi;
    int sz=vec.size();
    for(int i=1;i<sz;i++)
    {
        v.pb(vec[i]);
    }
    sort(v.begin(),v.end(),cmp2);
    int mxl=st.fi;
    int mnr=st.si;
    sz=v.size();
    set<pi>aux;
    for(int i=0;i<sz;i++)
    {
        int lft=v[i].fi.fi;
        int rgt=v[i].fi.si;
        int id=v[i].si;
        aux.insert(mp(lft,id));
    }
    while(v.size())
    {
        pi one=*aux.rbegin();
        int mxL=one.fi;
        int mnR=v[0].fi.si;
        int cost=fnd(mnR,mxL)+fnd(mnr,mxl);
        ses=max(ses,cost);
        int last_r=v.back().fi.si;
        int last_l=v.back().fi.fi;
        int last_id=v.back().si;
        v.pop_back();
        if(last_r<mnr)
        {
            mnr=last_r;
        }
        aux.erase(mp(last_l,last_id));
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 28280