#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1;

struct Inter {
    int l, r;
    Inter() {}
    Inter(int l, int r): l(l), r(r) {}
};

ostream& operator <<(ostream& out, Inter A) {
    out << "(" << A.l << ", " << A.r << ")";
    return out;
}

Inter intersection(Inter A, Inter B) {
    return {max(A.l, B.l), min(A.r, B.r)};
}

int len(Inter A) {
    return max(0, A.r-A.l + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    int N;
    cin >> N;
    vector<Inter> I(N);
    for (int i = 0; i < N; i++) cin >> I[i].l >> I[i].r;
    sort(I.begin(), I.end(), [](Inter A, Inter B) { return A.r > B.r; });
    Inter F = I.back();
    I.pop_back();
    Inter res2(-1, 1e9);
    sort(I.begin(), I.end(), [](Inter A, Inter B) { return A.l < B.l; });
    int res = 0;
    for (int i = N-2; i >= 0; i--) {
        Inter res1 = F;
        if (i >= 1) res1 = intersection(F, I[i-1]);
        res2 = intersection(I[i], res2);
        // dbg(res1, res2);
        res = max(len(res1)  + len(res2), res);
    }

    vector<Inter> i_before(N-1);
    vector<Inter> i_after(N-1);
    i_before[0] = F;
    i_after[N-2] = F;
    for (int i = 1; i < N-1; i++) i_before[i] = intersection(i_before[i-1], I[i-1]);
    for (int i = N-3; i >= 0; i--) i_after[i] = intersection(i_after[i+1], I[i+1]);

    for (int i = 0; i < N-1; i++) {
        res = max(res, len(I[i]) + len(intersection(i_before[i], i_after[i])));
    }
    
    cout << res << "\n";

    // cout << F << endl;
    // cout << I << endl;
}


Measured memory_bytes: 2560