///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#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                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n;
    cin>>n;
    int l[M+2],r[M+5];
    int mx=0,mx_id;
    int LP,RQ,LMX=0,RMN=inf;
    f(i,1,n)
    {
        cin>>l[i]>>r[i];
        int len=r[i]-l[i]+1;
        if(len>=mx)
        {
            mx=len;
            mx_id=i;
        }
    }
    int mx_lft=0,mn_rgt=inf,ses=0;
    for(int i=1;i<=n;i++)
    {
         if(mx_id==i)continue;
         mx_lft=max(l[i],mx_lft);
         mn_rgt=min(r[i],mn_rgt);
    }
    ses=mx+max(mn_rgt-mx_lft+1,0LL);
    f(i,1,n)
    {
        if(l[i]>LMX)
        {
            LMX=l[i];
            LP=i;
        }
        else if(l[i]==LMX)
        {
              if(r[i]>r[LP])
              {
                  LP=i;
              }
        }
        if(r[i]<RMN)
        {
            RQ=i;
            RMN=r[i];
        }
        else if(r[i]==RMN)
        {
            if(l[i]<l[RQ])
            {
                RQ=i;
            }
        }
    }
    if(LP==RQ)
    {
        cout<<ses<<endl;
        return 0;
    }
    vector<pi>vec;
    for(int i=1;i<=n;i++)
    {
        if(i==LP)continue;
        if(i==RQ)continue;
        vec.pb(mp(l[i],r[i]));
    }
    sort(vec.begin(),vec.end());
    int sz=vec.size();
    if(sz==0)
    {
        int x=r[LP]-l[LP]+1;
        int y=r[RQ]-l[RQ]+1;
        ses=max(ses,x+y);
        cout<<ses<<endl;
        return 0;
    }
    int suf[sz+5];
    suf[sz-1]=vec[sz-1].si;
    suf[sz]=inf;
    rf(i,sz-2,0)
    {
        suf[i]=min(suf[i+1],vec[i].si);
    }
    f(i,0,sz-1)
    {
        int lmx=max(vec[i].fi,l[RQ]);
        int x=max(RMN-lmx+1,0LL);
        int rmn=min(suf[i+1],r[LP]);
        int y=max(rmn-LMX+1,0LL);
        ses=max(ses,x+y);
        if(i==0)
        {
          lmx=l[RQ];
          x=max(RMN-lmx+1,0LL);
          rmn=min(suf[i],r[LP]);
          y=max(rmn-LMX+1,0LL);
          ses=max(ses,x+y);
        }
    }

    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 4336