// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

/**
 * @brief 1 次元累積和 (1 Dimension Cumulative Sum)
 * @docs ./docs/cumulative_sum.md
 */

#include <functional>
#include <vector>
template <typename MonoidType>
struct CumulativeSum {
    int n;
    vector<MonoidType> pre, suf;
    MonoidType E;
    
    using MMtoM = function< MonoidType(MonoidType, MonoidType) >;
    MMtoM op, rop;

    void accumulate() {
        int m = pre.size();
        for(int i=0; i+1<m; i++) {
            pre[i+1] = op(pre[i+1], pre[i]);
        }
        for(int i=m-2; i>=0; i--) {
            suf[i] = op(suf[i], suf[i+1]);
        }
    }

    CumulativeSum() {}
    CumulativeSum(vector<MonoidType> val_array, MonoidType E_,
                  MMtoM op_, MMtoM rop_ = MMtoM(),
                  bool need_accumulate = true) :
        E(E_), op(op_), rop(rop_) {
        n = val_array.size();
        pre = suf = vector<MonoidType>(n+2, E);
        for(int i=0; i<n; i++) pre[i+1] = suf[i+1] = val_array[i];
        if(need_accumulate) accumulate();
    }

    void range_apply(int l, int r, MonoidType val) {
        pre[l+1] = op(pre[l+1], val);
        pre[r+1] = rop(pre[r+1], val);
        suf[r] = op(suf[r], val);
        suf[l] = rop(suf[l], val);
    }

    // [0, k)
    inline MonoidType get_prefix(int k) { return 0 <= k and k <= n ? pre[k] : E; }
    // [k, n)
    inline MonoidType get_suffix(int k) { return 0 <= k and k <= n ? suf[k+1] : E; }
    // [l, r) (rop が定義されてるときのみ)
    inline MonoidType get_subseq(int l, int r) {
        return rop(get_prefix(r), get_prefix(l));
    }
};


int main() {
    int N; scanf("%d", &N);
    vector< pair<ll, ll> > segs(N);
    for(int i=0; i<N; i++) {
        int l, r; scanf("%d%d", &l, &r);
        segs[i] = make_pair(l, r+1);
    }
    sort(segs.begin(), segs.end());
    
    auto op_f = [&](pair<ll, ll> a, pair<ll, ll> b) {
        return make_pair(
            max(a.first, b.first),
            min(a.second, b.second)
            );
    };
    
    CumulativeSum< pair<ll, ll> > cumsum(segs,
                                         pair<ll, ll>(-LONGINF, LONGINF),
                                         op_f);
    ll ans = 0;
    for(int i=0; i<N; i++) {
        if(i+1 < N) {
            pair<ll, ll> s1 = cumsum.get_prefix(i+1);
            pair<ll, ll> s2 = cumsum.get_suffix(i+1);

            ll cand = max(0LL, s1.second - s1.first)
                + max(0LL, s2.second - s2.first);
            chmax(ans, cand);
        }
        {
            pair<ll, ll> s1 = cumsum.get_prefix(i);
            pair<ll, ll> s2 = cumsum.get_suffix(i+1);
            pair<ll, ll> s = op_f(s1, s2);
            ll cand = max(0LL, s.second - s.first)
                + max(0LL, segs[i].second - segs[i].first);
            chmax(ans, cand);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 9616