#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL << 50;

template <typename T>
class SegTree {
    private:
        size_t node_size;
        vector<T> node;
        T identity;                     // ex) INF, 0, etc...
        function<T(T, T)> operation;    // ex) min, max, sum, etc...
        function<T(T, T)> update;       // ex) add, change, etc..
    public:
        SegTree(size_t _node_size, T _identity, function<T(T, T)> _operation, function<T(T, T)> _update):
        identity(_identity), operation(_operation), update(_update) {
            node_size = 1;
            while (node_size < _node_size) node_size *= 2;
            node = vector<T>(2 * node_size - 1, identity);
        }
        void change(int idx, T new_value) {
            int node_idx = idx + node_size - 1;
            node[node_idx] = update(node[node_idx], new_value);
            while (node_idx > 0) {
                node_idx = (node_idx - 1) / 2;
                node[node_idx] = operation(node[node_idx * 2 + 1], node[node_idx * 2 + 2]);
            }
        }
        T _query(int left, int right, int node_idx, int node_left, int node_right) {
            // interval [node_left, node_right) corresponds to node_idx
            if (node_right <= left || right <= node_left) {
                return identity;
            }
            if (left <= node_left && node_right <= right) {
                return node[node_idx];
            }
            else {
                T left_value = _query(left, right, node_idx * 2 + 1, node_left, (node_left + node_right) / 2);
                T right_value = _query(left, right, node_idx * 2 + 2, (node_left + node_right) / 2, node_right);
                return operation(left_value, right_value);
            }
        }
        T query(int left, int right) {
            return _query(left, right, 0, 0, node_size);
        }
        T operator[](int idx) {
            return node[idx + node_size - 1];
        }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> L(N), R(N);
    rep(i, 0, N) cin >> L[i] >> R[i];
    SegTree<ll> lseg(N, 0, [](ll a, ll b){return max(a, b);}, [](ll a, ll b){return b;});
    SegTree<ll> rseg(N, INF, [](ll a, ll b){return min(a, b);}, [](ll a, ll b){return b;});
    vector<P> interval(N);
    rep(i, 0, N) {
        interval[i].first = L[i];
        interval[i].second = R[i];
    }
    sort(all(interval));
    rep(i, 0, N) {
        lseg.change(i, interval[i].first);
        rseg.change(i, interval[i].second);
    }
    ll ans = 0;
    rep(i, 0, N) {
        ll other = 0;
        if (i > 0 && i + 1 < N) {
            other = max(min(rseg.query(0, i), rseg.query(i + 1, N)) - max(lseg.query(i + 1, N), lseg.query(0, i)) + 1, 0LL);
        }
        ans = max(ans, interval[i].second - interval[i].first + 1 + other);
    }
    rep(i, 1, N) {
        ll lmax1 = lseg.query(0, i), rmin1 = rseg.query(0, i);
        ll lmax2 = lseg.query(i, N), rmin2 = rseg.query(i, N);
        ans = max(ans, max(rmin1 - lmax1 + 1, 0LL) + max(rmin2 - lmax2 + 1, 0LL));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9600