#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;
vector<vector<int> >query;
pii A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1,idy = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    vector<int> val;

    for(int i=0;i<n;i++){
        cin>>A[i].f>>A[i].s;
        val.push_back(A[i].f);
        val.push_back(A[i].s);
    }

    if(n==2){
        int res = A[1].s-A[1].f+1+A[0].s-A[0].f+1;
        cout<<res<<"\n";
        return 0;
    }

    sort(val.begin(),val.end());
    val.erase(unique(val.begin(),val.end()),val.end());

    for(int i=0;i<n;i++){
        idx = lower_bound(val.begin(),val.end(),A[i].f)-val.begin();
        idy = lower_bound(val.begin(),val.end(),A[i].s)-val.begin();
        A[i].f = idx;
        A[i].s = idy;
    }

    int mxx = -1;
    int mxy = -1;
    int mnx = INF;
    int mny = INF;
    int mxid = -1;
    int mnid = -1;

    for(int i=0;i<n;i++){
        if(A[i].f>mxx){
            mxx = A[i].f;
            mxy = A[i].s;
            mxid = i;
        }
        else if(mxx==A[i].f){
            if(mxy<A[i].s){
                mxy = A[i].s;
                mxid = i;
            }
        }
    }

    for(int i=0;i<n;i++){
        if(A[i].s<mny){
            mnx = A[i].f;
            mny = A[i].s;
            mnid = i;
        }
        else if(mny==A[i].s){
            if(mnx>A[i].f){
                mnx = A[i].f;
                mnid = i;
            }
        }
    }

    if(mxid==mnid){
        a = A[mxid].f;
        b = A[mxid].s;
        int res = val[b]-val[a]+1;

        for(int i=0;i<n;i++){
            a = A[i].f;
            b = A[i].s;
            mx = max(mx,val[b]-val[a]+1);
        }

        cout<<res+mx<<"\n";

        return 0;
    }

    int sz = val.size();

    query = vector<vector<int> > (sz);

    for(int i=0;i<n;i++){
        if(i==mxid||i==mnid)continue;
        query[A[i].s].push_back(A[i].f);
    }

    a = A[mnid].f;
    b = A[mnid].s;

    int res = val[b]-val[a]+1;

    x = -1;
    y = INF;

    int inimax = 0;

    for(int i=0;i<n;i++){
        if(i==mxid||i==mnid)continue;
        x = A[i].f;
        y = A[i].s;
        inimax = max(inimax,val[y]-val[x]+1);
    }

    a = A[mxid].f;
    b = A[mnid].s;
    inimax += max(0,val[b]-val[a]+1);

    res = max(res,inimax);

    for(int i=0;i<mxx;i++){
        for(int j=0;j<query[i].size();j++){
            cur = query[i][j];
            mnx = max(mnx,cur);
        }
    }

    for(int i=mxx;i<=mxy;i++){

        cur = max(val[mny]-val[mnx]+1,0)+val[i]-val[mxx]+1;

        res = max(res,cur);

        for(int j=0;j<query[i].size();j++){
            mnx = max(mnx,query[i][j]);
        }
    }

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 9716