// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

int main() {
    ll N;
    cin >> N;
    V<PLL> lr(N);
    multiset<ll, greater<ll>> lset;
    multiset<ll> rset;
    for(auto &&ele : lr) {
        ll l, r;
        cin >> l >> r;
        lset.insert(l);
        rset.insert(r);
        ele = PLL(l, r);
    }
    
    auto del_l = [&](ll l) {
        auto ite = lset.find(l);
        lset.erase(ite);
    };

    auto del_r = [&](ll r) {
        auto ite = rset.find(r);
        rset.erase(ite);
    };

    ll l1, r1, ans = 0;
    auto update_ans = [&] {
        ll rng1 = max<ll>(0, r1 - l1 + 1);
        ll rng2 = max<ll>(0, (*rset.begin()) - (*lset.begin()) + 1);
        chmax(ans, rng1 + rng2);
    };

    for(auto &&ele : lr) {
        tie(l1, r1) = ele;
        del_l(l1);
        del_r(r1);
        update_ans();
        lset.insert(l1);
        rset.insert(r1);
    }

    {
        auto ite = 
            min_element(ALL(lr),
                        [](PLL p, PLL q) {
                            ll lp, lq, rp, rq;
                            tie(lp, rp) = p;
                            tie(lq, rq) = q;
                            if(lp != lq) return lp > lq;
                            else return rp < rq;
                        });
        tie(l1, r1) = *ite;
        del_l(l1);
        del_r(r1);
        update_ans();
        lr.erase(ite);
    }

    sort(ALL(lr),
         [](PLL p, PLL q) {
             ll lp, rp, lq, rq;
             tie(lp, rp) = p;
             tie(lq, rq) = q;
             if(lp != lq) return lp > lq;
             else return rp < rq;
         });

    queue<PLL> lr_q;
    for(auto &&ele : lr) lr_q.push(ele);
    
    while(1 < lr_q.size()) {
        ll l, r;
        tie(l, r) = lr_q.front();
        chmax(l1, l);
        chmin(r1, r);
        del_l(l);
        del_r(r);
        lr_q.pop();
        update_ans();
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12800