#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

// hloya template v26
 
// ░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░
// ░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░
// ░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░
// ░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░
// █▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░
// ▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄
// ░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█
// ░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███
// ░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░
// ░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░
// ░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░

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

bool dbg = 0;
  
clock_t start_time = clock();
#define current_time fixed<<setprecision(6)<<(ld)(clock()-start_time)/CLOCKS_PER_SEC
  
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))


#define ull unsigned long long
#define ll long long
#define ld long double
#define pii pair<int,int>
#define umap unordered_map<int, int>
  
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
  
#define endl '\n'
#define ln(i,n) " \n"[(i) == (n) - 1]
  
void bad(string mes = "Impossible"){cout << mes;exit(0);}
void bad(int mes){cout << mes;exit(0);}
  
template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}
  
mt19937_64 mt_rand(
    chrono::system_clock::now().time_since_epoch().count()
);

template<typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); }
template<typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); }

// inline int popcount(int x){
//     int count = 0;
//     __asm__ volatile("POPCNT %1, %0;":"=r"(count):"r"(x):);
//     return count;
// }
  
template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';
  
    while (!((c >= '0' && c <= '9') || c == '-')) {
        c = getchar();
    }
  
    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + (c - '0'), c = getchar();
    }
    return ans * m;
}

template<typename T>
T gcd (T a, T b) { while (b) { a %= b; swap (a, b); } return a; }
  
template<typename T> void read(T& a) { a = input<T>(); }
template<typename T> void read(T& a, T& b) { read(a), read(b); }
template<typename T> void read(T& a, T& b, T& c) { read(a, b), read(c); }
template<typename T> void read(T& a, T& b, T& c, T& d) { read(a, b), read(c, d); }

const int inf = 1e9 + 20;
const short short_inf = 3e4 + 20;
const long double eps = 1e-12;
const int maxn = (int)1e6 + 3, base = 998244353;
const ll llinf = 2e18 + 5;

int binpow(int a, int s) { 
    int res = 1;
    while (s) {
        if (s % 2) {
            res = 1ll * res * a % base;
        }
        a = 1ll * a * a % base;
        s /= 2;
    }
    return res;
}


struct KMin {
    ll col1, col2;
    ll val1, val2;

    KMin(){ 
        val1 = val2 = llinf;
        col1 = col2 = -1;
    }

    void add(ll v, ll c) {
        if (v < val1) {
            swap(val1, val2);
            swap(col1, col2);
            swap(col1, c);
            swap(val1, v);
        } else if (v < val2) {
            swap(val2, v);
            swap(col2, c);
        }
    }

    void clear() {
        val1 = val2 = llinf;
        col1 = col2 = -1;
    }

    void add(KMin other) {
        if (other.val1 < val1) {
            swap(val1, val2);
            swap(col1, col2);
            swap(val1, other.val1);
            swap(col1, other.col1);
        } else if (other.val1 < val2) {
            swap(val2, other.val1);
            swap(col2, other.col1);
        }
        if (other.val2 < val2) {
            swap(val2, other.val2);
            swap(col2, other.col2);
        }
    }

    ll get(ll c) {
        return c == col1 ? val2 : val1;
    }
};

ll solve(ll n, vector<int> l, vector<int> r) {
    ll mr = llinf;
    ll idskip;
    
    KMin mml, mmr;

    for (ll i = 0; i < n; i++) {
        if (upmin(mr, r[i])) {
            idskip = i;
        }

        mmr.add(r[i], i);
        mml.add(-l[i], i);
    }
    
    ll ans = 0;

    for (ll i = 0; i < n; i++) {
        ll area1 = max(0, r[i] - l[i] + 1);
        ll area2 = max(0LL, mmr.get(i) + mml.get(i) + 1);
        upmax(ans, area1 + area2);
    }
    
    vector<pair<ll, ll>> evs;
    for (ll i = 0; i < n; i++) if (i != idskip) {
        evs.eb(l[i], i);
    }

    sort(all(evs));
    
    ll maxL = l[idskip];

    vector<ll> rm(evs.size(), llinf);
    for (ll i = evs.size() - 1; i >= 0; i--) {
        rm[i] = r[evs[i].second];
        if (i + 1 < evs.size()) {
            upmin(rm[i], rm[i + 1]);
        }
    }

    for (ll i = 0; i < evs.size(); i++) {
        // [i, ...]
        ll area1 = max(0LL, r[idskip] - maxL + 1);
        ll area2 = max(0LL, rm[i] - evs.back().first + 1);
        upmax(maxL, evs[i].first);
        upmax(ans, area1 + area2);
    }
    return ans;
}

int brute(int n, vector<int> l, vector<int> r) {
    int ans = 0;
    for (int mask = 1; mask < (1 << n) - 1; mask++) {
        int l1 = -inf, r1 = inf, l2 = -inf, r2 = inf;
        for (int i = 0; i < n; i++) {
            if (mask & (1 << i)) {
                upmax(l1, l[i]);
                upmin(r1, r[i]);
            } else {
                upmax(l2, l[i]);
                upmin(r2, r[i]);
            }
        }
        upmax(ans, max(0, r1 - l1 + 1) + max(0, r2 - l2 + 1));
    }
    return ans;
}

int main() {
    // files1;
    fast_io;

    int n;
    cin >> n;

    // if (n > 20) {
    //     throw;
    // }

    vector<int> l(n), r(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];
    }

    cout << solve(n, l, r);
    return 0;

    for (int iter = 0; iter < 100000; iter++) {
        int n = 17;
        vector<int> l, r;
        for (int i = 0; i < n; i++) {
            int x = rand() % 1000000000 + 1, y = rand() % 1000000000 + 1;
            if (x > y) swap(x, y);
            l.pb(x);
            r.pb(y);
        }
        if (iter % 1000 == 0) {
            cout << iter << " ok" << endl;
            cout.flush();
        }
        int a, b;
        if ((a = brute(n, l, r)) != (b = solve(n, l, r))) {
            for (int i = 0; i < n; i++) {
                cout << l[i] << ' ' << r[i] << "\n";
            }
            exit(228);
        }
    }
    return 0;
}

Measured memory_bytes: 4208