#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


#line 1 "lib/segment_tree.hpp"



#include <vector>
#include <algorithm>
#include <functional>

template<typename Monoid>
class SegmentTree {
public:
    using Operator = std::function<Monoid(Monoid, Monoid)>;

    SegmentTree(int n, const Operator &op, const Monoid init)
        : op(op), init(init) {

        num = 1;
        while (num < n) num *= 2;
        dat.resize(2 * num, init);
    }

    SegmentTree(const std::vector<Monoid> &m,
        const Operator &op, const Monoid init)
        : SegmentTree(m.size(), op, init) {

        int n = m.size();
        for (int i = 0; i < n; i++) {
            dat[num - 1 + i] = m[i];
        }
        for (int i = num - 2; i >= 0; i--) {
            dat[i] = op(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    // Update the k-th value (0-indexed) to a.
    void update(int k, Monoid a) {
        k += num - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // Get the value of the range [a, b).
    // k: The index of the node.
    // [left, right): The range corresponds to the k-th node.
    // Call like getval(a, b).
    Monoid getval(int a, int b, int k = 0, int left = 0, int right = -1) {
        if (right < 0) right = num;
        if (right <= a || b <= left) return init;
        if (a <= left && right <= b) return dat[k];
        Monoid vleft = getval(
            a, b, 2 * k + 1, left, left + (right - left) / 2);
        Monoid vright = getval(
            a, b, 2 * k + 2, left + (right - left) / 2, right);
        return op(vleft, vright);
    }

private:
    int num;
    std::vector<Monoid> dat;
    const Operator op;
    const Monoid init;
};


int main() {
    int n; std::cin >> n;
    using P = std::pair<long long, long long>;
    std::vector<P> lr(n);
    for (int i = 0; i < n; i++) {
        std::cin >> lr[i].first >> lr[i].second;
        lr[i].second++;
    }
    std::sort(lr.begin(), lr.end(), [](P &a, P &b) {
        return a.first == b.first ? a.second > b.second : a.first < b.first;
    });
    SegmentTree<P>
        seg(lr,
            [](const P &a, const P &b) -> P {
                return {
                    std::max(a.first, b.first),
                    std::min(a.second, b.second) };
            },
            { 0, 1e9 + 2 });
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long v = lr[i].second - lr[i].first;
        auto p = seg.getval(0, i), q = seg.getval(i + 1, n);
        v += std::max(0LL,
            std::min(p.second, q.second) - std::max(p.first, q.first));
        ans = std::max(ans, v);
    }
    for (int i = 0; i < n - 1; i++) {
        auto p = seg.getval(0, i + 1), q = seg.getval(i + 1, n);
        auto u = std::max(0LL, p.second - p.first);
        auto v = std::max(0LL, q.second - q.first);
        ans = std::max(ans, u + v);
    }
    std::cout << ans << std::endl;
    return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}