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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

const int MAX_N = 300000;
ll rmq_N;
ll rmq_dat[2*MAX_N-1];

// 要素数n_で初期化
void rmq_init(ll n_) {
    // rmq_Nを2のべき乗にする
    rmq_N = 1;
    while(rmq_N < n_) rmq_N *= 2;
    rep(i,2*rmq_N-1) rmq_dat[i] = LINF;
}

// k番目の値をaに変更
void rmq_update(ll k, ll a) {
    k += rmq_N - 1;
    rmq_dat[k] = a;
    while (k > 0) {
        k = (k - 1) / 2;
        rmq_dat[k] = min(rmq_dat[k * 2 + 1], rmq_dat[k * 2 + 2]);
    }
}

// [a, b)の最小値を求める
// 接点の番号k，subとして[l,r)の最小値を求めてる
ll rmq_query(ll a, ll b, ll k, ll l, ll r) {
    if (r<=a || b<=l) return LINF;
    if (a<=l && r<=b) return rmq_dat[k];
    else {
        ll vl = rmq_query(a,b,k*2+1,l,(l+r)/2);
        ll vr = rmq_query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

bool pairCompare1(const pll& Fir, const pll& Sec)
{
    return Fir.second < Sec.second; // 2番目について昇順
}
bool pairCompare2(const pll& Fir, const pll& Sec)
{
    return Fir.first > Sec.first; // 1番目について降順
}

int main() {
    ll N;
    cin >> N;
    vector<pll> len;
    rep(i,N) {
        ll L, R;
        cin >> L >> R;
        R++;
        len.push_back(make_pair(L,R));
    }
    sort(len.begin(), len.end(), pairCompare1);
    ll Rp = len[0].second;
    ll Lp = len[0].first;
    REP(i,1,N) {
        if (len[i].second == Rp) {
            if(len[i].first > Lp) {
                Lp = len[i].first;
            }
        } else {
            break;
        }
    }
    sort(len.begin(), len.end(), pairCompare2);
    ll Lq = len[0].first;
    ll Rq = len[0].second;
    REP(i,1,N) {
        if (len[i].first == Lq) {
            if(len[i].second < Rq) {
                Rq = len[i].second;
            }
        } else {
            break;
        }
    }

    sort(len.begin(), len.end(), pairCompare1);

    int pind = -1;
    int qind = -1;
    rep(i,N) {
        if(Lp == len[i].first && Rp == len[i].second && pind < 0) {
            pind = i;
        }
        if(Lq == len[i].first && Rq == len[i].second && qind < 0) {
            qind = i;
        }
    }

    // pとqが同じグループに入る
    ll ans1 = 0;
    if (Rp-Lq> 0) ans1 += Rp - Lq;
    ll dif_max = 0;
    rep(i,N) {
        if(i == qind) continue;
        if(i == pind) continue;
        if(dif_max < len[i].second - len[i].first) {
            dif_max = len[i].second - len[i].first;
        }
    }
    ans1 += dif_max;

    if(pind == qind) {
        cout << ans1 << endl;
        return 0;
    }

    if(pind != qind && N == 2) {
        ans1 = 0;
    }


    // pとqが違うグループ
    vector<pll> AB(N);
    rep(i,N) {
        ll A = 0;
        ll B = 0;
        if (Rp - len[i].first > 0) A = Rp - len[i].first;
        if (len[i].second - Lq > 0) B = len[i].second - Lq;
        if(i == qind) A = -1 * LINF;
        AB[i] = make_pair(A, B);
    }
    sort(AB.begin(), AB.end(), pairCompare2);
    ll ans2 = 0;
    rmq_init(N);
    rep(i,N) {
        rmq_update(i, AB[i].second);
    }
    rep(i, N-1) {
        ll mina = AB[i].first;
        ll minb = rmq_query(i+1, N, 0, 0, rmq_N);
        ans2 = max(mina + minb, ans2);
    }
    ll ans = max(ans1, ans2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7536