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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }



void func(long long N, std::vector<long long> L, std::vector<long long> R){

    lli ans = -INF;
{
    vector<pair<lli,lli>> v;
    REP(i,0,N)v.push_back({L[i],R[i]});
    
    sort(v.begin(),v.end());

    lli lMax,rMin;
    multiset<lli> rMinS[2];
    multiset<lli,greater<lli>> lMaxS[2];

    lMaxS[0].insert(v[0].first);
    rMinS[0].insert(v[0].second);

    REP(i,1,N){
        lMaxS[1].insert(v[i].first);
        rMinS[1].insert(v[i].second);
    }

    REP(i,1,N){
        lli sum = 0;
        REP(j,0,2){
            auto lMaxItr = lMaxS[j].begin();
            auto rMaxItr = rMinS[j].begin();
            LOG3(j,(*rMaxItr),(*lMaxItr));
            sum += max((*rMaxItr)-(*lMaxItr)+1,0LL);
            //sum++;
        }
        LOG3(i,ans,sum);
        ans = max(ans, sum);
        
        lMaxS[0].insert(v[i].first);
        lMaxS[1].erase(lMaxS[1].find(v[i].first));

        rMinS[0].insert(v[i].second);
        rMinS[1].erase(rMinS[1].find(v[i].second));
    
    }
}
{
    vector<pair<lli,lli>> v;
    REP(i,0,N)v.push_back({L[i],R[i]});
    
    sort(v.begin(),v.end());

    lli lMax,rMin;
    multiset<lli> rMinS[2];
    multiset<lli,greater<lli>> lMaxS[2];

    lMaxS[0].insert(v[0].first);
    rMinS[0].insert(v[0].second);

    REP(i,1,N){
        lMaxS[1].insert(v[i].first);
        rMinS[1].insert(v[i].second);
    }

    REP(i,1,N){
        lli sum = 0;
        REP(j,0,2){
            auto lMaxItr = lMaxS[j].begin();
            auto rMaxItr = rMinS[j].begin();
            LOG3(j,(*rMaxItr),(*lMaxItr));
            sum += max((*rMaxItr)-(*lMaxItr)+1,0LL);
            //sum++;
        }
        LOG3(i,ans,sum);
        ans = max(ans, sum);
        
        lMaxS[0].insert(v[i].first);
        lMaxS[0].erase(lMaxS[0].find(v[i-1].first));
        lMaxS[1].insert(v[i-1].first);
        lMaxS[1].erase(lMaxS[1].find(v[i].first));

        rMinS[0].insert(v[i].second);
        rMinS[0].erase(rMinS[0].find(v[i-1].second));
        rMinS[1].insert(v[i-1].second);
        rMinS[1].erase(rMinS[1].find(v[i].second));
    
    }
}
    cout<<ans<<endl;


}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    std::vector<long long> R(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
    }
    func(N, std::move(L), std::move(R));
    return 0;
}


Measured memory_bytes: 12784