#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

template <typename T>
class SegmentTree {
   private:
    size_t length;
    vector<T> data;
    T e;
    function<T(T, T)> f;
    //data[i]の区間 = [l[i],r[i])
    vector<int> l;
    vector<int> r;

   public:
    void
    change(int i, T val) {
        data[i + length - 1] = val;
        for (int k = (i + length) / 2 - 1; k >= 0; k = (k - 1) / 2) {
            data[k] = f(data[2 * k + 1], data[2 * k + 2]);
            if (!k) break;
        }
    }

    //[i,j)
    T query(const int& i, const int& j) {
        T ans = e;
        queue<int> que;
        que.push(0);
        int k;
        while (que.size()) {
            k = que.front();
            que.pop();
            if (r[k] <= i || j <= l[k]) {
                continue;
            }
            if (i <= l[k] && r[k] <= j) {
                ans = f(ans, data[k]);
                continue;
            }
            que.push(2 * k + 1);
            que.push(2 * k + 2);
        }
        return ans;
    }

    T operator[](const size_t& i) {
        return data[i + length - 1];
    }

    SegmentTree(const vector<T>& v, const function<T(T, T)>& f, const T& e) : length(1), f(f), e(e) {
        while (!(length >= v.size())) length *= 2;
        data = vector<T>(length * 2 - 1, e);
        for (int i = 0; i < v.size(); i++) {
            data[i + length - 1] = v[i];
        }
        for (int i = length - 2; 0 <= i; i--) {
            data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
        }
        l.resize(length * 2 - 1);
        r.resize(length * 2 - 1);
        for (int i = length - 1; i < length * 2 - 1; i++) {
            l[i] = i - length + 1;
            r[i] = min(i - length + 2, v.size());
        }
        for (int i = length - 2; 0 <= i; i--) {
            l[i] = l[i * 2 + 1];
            r[i] = r[i * 2 + 2];
        }
    };
};

/* main */

ll len(ll L, ll R) {
    return max(R - L + 1, 0);
}

ll solve(ll N, vector<pl> v) {
    sort(ALL(v));
    auto f = [](pl p1, pl p2) { return make_pair(max(p1.first, p2.first), min(p1.second, p2.second)); };
    auto e = make_pair(numeric_limits<ll>::min(), numeric_limits<ll>::max());
    SegmentTree<pl> st(v, f, e);
    ll ans = numeric_limits<ll>::min();
    for (size_t i = 0; i < N - 1; i++) {
        ll L = st[i].first;
        ll R = st[i].second;
        ll left_R = st.query(0, i).second;
        pl right = st.query(i + 1, N);
        ll tmp1 = len(L, min(left_R, R)) + len(right.first, right.second);
        ll tmp2 = len(L, R) + len(right.first, min(left_R, right.second));
        ans = max({ans, tmp1, tmp2});
    }
    return ans;
}

vector<vector<long long>> base(long long n, long long N) {
    long long SIZE = 1;
    for (long long i = 0; i < N; i++) SIZE *= n;
    vector<vector<long long>> ans(SIZE, vector<long long>());
    for (long long rep = 0; rep < N; rep++) {
        SIZE /= n;
        for (long long i = 0; i < ans.size(); i++) {
            ans[i].push_back((i / SIZE) % n);
        }
    }
    return ans;
}

ll guchoku(ll N, vector<pl> v) {
    ll ans = 0;
    auto e = base(2, N);
    auto f = [](pl p1, pl p2) { return make_pair(max(p1.first, p2.first), min(p1.second, p2.second)); };
    auto e_ = make_pair(numeric_limits<ll>::min(), numeric_limits<ll>::max());
    for (size_t i = 0; i < e.size(); i++) {
        map<ll, ll> m;
        for (auto x : e[i]) m[x]++;
        if (!m[0] || !m[1]) {
            continue;
        }
        pl p1 = e_, p2 = e_;
        for (size_t j = 0; j < e[i].size(); j++) {
            if (e[i][j]) {
                p1 = f(p1, v[j]);
            } else {
                p2 = f(p2, v[j]);
            }
        }
        ans = max(ans, len(p1.first, p1.second) + len(p2.first, p2.second));
    }
    return ans;
}

signed main() {
    ll N;
    cin >> N;
    vector<pl> v;
    for (size_t i = 0; i < N; i++) {
        ll L, R;
        cin >> L >> R;
        v.push_back(make_pair(L, R));
    }
    cout << solve(N, v) << endl;
}

Measured memory_bytes: 9940