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

int main(){
    int n, ls[100000], rs[100000];
    cin >> n;
    for(int i=0;i<n;++i) cin >> ls[i] >> rs[i];

    int l=1, r=1000000000, li, ri, dm=0;
    for(int i=0;i<n;++i){
        dm = max(dm, rs[i]-ls[i]+1);
        if(ls[i] >= l){
            l = ls[i];
            li = i;
        }
        if(rs[i] <= r){
            r = rs[i];
            ri = i;
        }
    }
    int cand = max(0, r-l+1) + dm;
    vector<pair<int,int>> ov;
    if(l > r){
        int ll = ls[ri], lr = rs[ri], rl = ls[li], rr = rs[li];
        for(int i=0;i<n;++i){
            if(rs[i] < l){
                ll = max(ll, ls[i]);
                lr = min(lr, rs[i]);
            }else if(ls[i] > r){
                rl = max(rl, ls[i]);
                rr = min(rr, rs[i]);
            }else{
                ov.emplace_back(ls[i], rs[i]);
            }
        }
        if(ll>lr || rl>rr){
            cout << cand << endl;
            return 0;
        }
        sort(ov.begin(), ov.end(), [&lr, &rl](auto x, auto y){
            int xl = max(0, lr-x.first+1);
            int yl = max(0, lr-y.first+1);
            int xr = max(0, x.second-rl+1);
            int yr = max(0, y.second-rl+1);
            if(xl==yl) return xr < yr;
            else return xl > yl;
        });
        vector<int> len_l(ov.size()+1), len_r(ov.size()+1);
        len_l[0] = max(0, lr-ll+1);
        for(int i=1;i<=ov.size();++i){
            ll = max(ll, ov[i-1].first);
            len_l[i] = max(0, lr-ll+1);
        }
        len_r[ov.size()] = max(0, rr-rl+1);
        for(int i=1;i<=ov.size();++i){
            rr = min(rr, ov[ov.size()-i].second);
            len_r[ov.size()-i] = max(0, rr-rl+1);
        }
        int ans = 0;
        for(int i=0;i<=ov.size();++i) ans = max(ans, len_l[i]+len_r[i]);
        cerr << ans << " " << cand << endl;
        cout << max(ans, cand) << endl;
        return 0;
    }else if(li == ri){
        cout << cand << endl;
        return 0;
    }else{
        int ll = ls[ri], lr = rs[ri], rl = ls[li], rr = rs[li];
        for(int i=0;i<n;++i){
            if(rs[i] < l){
                ll = max(ll, ls[i]);
                lr = min(lr, rs[i]);
            }else if(ls[i] > r){
                rl = max(rl, ls[i]);
                rr = min(rr, rs[i]);
            }else{
                ov.emplace_back(ls[i], rs[i]);
            }
        }
        if(ll>lr || rl>rr){
            cout << cand << endl;
            return 0;
        }
        sort(ov.begin(), ov.end(), [&lr, &rl](auto x, auto y){
            int xl = max(0, lr-x.first+1);
            int yl = max(0, lr-y.first+1);
            int xr = max(0, x.second-rl+1);
            int yr = max(0, y.second-rl+1);
            if(xl==yl) return xr < yr;
            else return xl > yl;
        });
        vector<int> len_l(ov.size()+1), len_r(ov.size()+1);
        len_l[0] = max(0, lr-ll+1);
        for(int i=1;i<=ov.size();++i){
            ll = max(ll, ov[i-1].first);
            len_l[i] = max(0, lr-ll+1);
        }
        len_r[ov.size()] = max(0, rr-rl+1);
        for(int i=1;i<=ov.size();++i){
            rr = min(rr, ov[ov.size()-i].second);
            len_r[ov.size()-i] = max(0, rr-rl+1);
        }
        int ans = 0;
        for(int i=0;i<=ov.size();++i) ans = max(ans, len_l[i]+len_r[i]);
        cerr << ans << " " << cand << endl;
        cout << max(ans, cand) << endl;
        return 0;
    }
    
    return 0;
}

Measured memory_bytes: 2548