#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

class Match {

    multiset<ll> l, r;


public:
    void add(P p) {
        this->l.insert(p.first);
        this->r.insert(p.second);
    }

    ll point() {
        auto itl = l.end();
        itl--;
        ll lr = *itl;
        auto itr = r.begin();
        ll rl = *itr;

        return max<ll>(rl - lr + 1, 0);
    }

    void pop(P p) {
        l.erase(l.find(p.first));
        r.erase(r.find(p.second));
    }


};

int main() {
    int n;
    cin >> n;
    vector<P> v(n);
    for (P &p:v)cin >> p.first >> p.second;

    ll ans_one = [&] {
        Match a, b;
        rep(i, n) {
            b.add(v[i]);
        }

        ll ans = 0;
        rep(i, n) {
            b.pop(v[i]);
            a.add(v[i]);

            ll now = b.point() + a.point();
            cmax(ans, now);

            a.pop(v[i]);
            b.add(v[i]);
        }
        return ans;
    }();

    ll ans_split = [&]() -> ll {

        sort(v.begin(), v.end(), [](P p1, P p2) {
            return p1.second < p2.second;
        });

        Match a, b;
        for (P p : v) b.add(p);
        ll ans = 0;
        rep(i, n - 1) {
            P p = v[i];
            a.add(p);
            b.pop(p);
            ll now = a.point() + b.point();
            cmax(ans, now);
        }
        return ans;
    }();

    ll ans = max(ans_split, ans_one);

    cout << ans << endl;

}

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


template <typename T>
struct DisjointSparseTable{
    function<T(T, T)> f;
    vector<vector<T>> v;

    DisjointSparseTable(vector<T>& inp, function<T(T, T)> f) : f(f){
        int n = inp.size();
        int b;
        for(b = 0; (1 << b) <= inp.size(); ++b);
        v.assign(b, vector<T>(n));
        for(int i = 0; i < n; ++i)
            v[0][i] = inp[i];
        for(int i = 1; i < b; ++i){
            int siz = 1 << i;
            for(int j = 0; j < n; j += siz << 1){
                int t = min(j + siz, n);
                v[i][t - 1] = inp[t - 1];
                for(int k = t - 2; k >= j; --k)
                    v[i][k] = f(inp[k], v[i][k + 1]);
                if(t >= n)
                    break;
                v[i][t] = inp[t];
                int r = min(t + siz, n);
                for(int k = t + 1; k < r; ++k)
                    v[i][k] = f(v[i][k - 1], inp[k]);
            }
        }
    }

    T get(int l, int r){
        if(l >=r)
            return MOD;
        if(l >= --r)
            return v[0][l];
        int p = 31 - __builtin_clz(l ^ r);
        return f(v[p][l], v[p][r]);
    }
};



signed main(){

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

    int l_ma = 0, l_ma_idx = 0;
    int r_mi = MOD, r_mi_idx = 0;
    for(int i = 0; i < n; ++i){
        if(chmax(l_ma, l[i]))
            l_ma_idx = i;
        if(chmin(r_mi, r[i]))
            r_mi_idx = i;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(i != l_ma_idx && i != r_mi_idx)
            chmax(ans, max(r_mi - l_ma, 0) + r[i] - l[i]);
    }
    if(l_ma_idx != r_mi_idx){
        vector<pair<int,int>> v;
        for(int i = 0; i < n; ++i){
            if(i != l_ma_idx && i != r_mi_idx){
                // 一定までfirstを、それ以降はsecondを見て、総和の最大化をする
                v.emplace_back(max(0, r[i] - l_ma), max(0, r_mi - l[i]));
            }
        }
        sort(v.begin(), v.end(), greater<>());
        int m = v.size();
        vector<int> v1, v2;
        for(int i = 0; i < m; ++i){
            v1.push_back(v[i].first);
            v2.push_back(v[i].second);
        }
        DisjointSparseTable<int> d1(v1, [](auto x, auto y){return min(x, y);});
        DisjointSparseTable<int> d2(v2, [](auto x, auto y){return min(x, y);});
        for(int i = 0; i <= m; ++i){
            chmax(ans, min(d1.get(0, i), r[l_ma_idx] - l[l_ma_idx]) + min(d2.get(i, m), r[r_mi_idx] - l[r_mi_idx]));
        }
    }
    cout << ans << endl;

}

