#include <bits/stdc++.h>

typedef long double ld;
typedef long long ll;

const int inf = 1e9 + 1;
const ld pi = acos(-1);

using namespace std;

bool cmp(pair<int, int> left, pair<int, int> right) {
    return left.second < right.second;
}
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    cout << setprecision(20);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    int mx = 0;
    int mxj = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        if (mx < a[i].second - a[i].first) {
            mx = a[i].second - a[i].first;
            mxj = i;
        }
    }
    mx++;
    {
        int mxs = 0;
        int mns = 1e9 + 1;
        for (int i = 0; i < n; i++) {
            if (i != mxj) {
                if (mns > a[i].second) {
                    mns = a[i].second;
                }
                if (mxs < a[i].first) {
                    mxs = a[i].first;
                }
            }
        }
        mx += max(0, mns - mxs + 1);
//        cout << mns << " " << mxs << " " << mxj << endl;
    }

    sort(a.begin(), a.end());
    {
        int ans = 0;
        multiset<int> left1;
        multiset<int> left2;
        multiset<int> right1;
        multiset<int> right2;
        for (int i = 1; i < n; i++) {
            right1.insert(a[i].first);
            right2.insert(a[i].second);
        }
        left1.insert(a[0].first);
        left2.insert(a[0].second);

        for (int i = 1; i < n - 1; i++) {
            int mn2, mx2, mn1, mx1;
            mn1 = *(left2.begin());
            auto it1 = left1.end();
            it1--;
            mx1 = *(it1);
            mn2 = *(right2.begin());
            auto it2 = right1.end();
            it2--;
            mx2 = *(it2);
            int locans = max(0, mn1 - mx1 + 1) + max(0, mn2 - mx2 + 1);
            if (locans > ans) {
                ans = locans;
            }
            left1.insert(a[i].first);
            left2.insert(a[i].second);
            right1.erase(right1.find(a[i].first));
            right2.erase(right2.find(a[i].second));
        }
        int mn2, mx2, mn1, mx1;
        mn1 = *(left2.begin());
        auto it1 = left1.end();
        it1--;
        mx1 = *(it1);
        mn2 = *(right2.begin());
        auto it2 = right1.end();
        it2--;
        mx2 = *(it2);
        int locans = max(0, mn1 - mx1 + 1) + max(0, mn2 - mx2 + 1);
        if (locans > ans) {
            ans = locans;
        }
        mx = max(ans, mx);
    }
    //cout << mx;
    sort(a.begin(), a.end(), cmp);
    {
        int ans = 0;
        multiset<int> left1;
        multiset<int> left2;
        multiset<int> right1;
        multiset<int> right2;
        for (int i = 1; i < n; i++) {
            right1.insert(a[i].first);
            right2.insert(a[i].second);
        }
        left1.insert(a[0].first);
        left2.insert(a[0].second);

        for (int i = 1; i < n - 1; i++) {
            int mn2, mx2, mn1, mx1;
            mn1 = *(left2.begin());
            auto it1 = left1.end();
            it1--;
            mx1 = *(it1);
            mn2 = *(right2.begin());
            auto it2 = right1.end();
            it2--;
            mx2 = *(it2);
            int locans = max(0, mn1 - mx1 + 1) + max(0, mn2 - mx2 + 1);
            if (locans > ans) {
                ans = locans;
            }
            left1.insert(a[i].first);
            left2.insert(a[i].second);
            right1.erase(right1.find(a[i].first));
            right2.erase(right2.find(a[i].second));
        }
        int mn2, mx2, mn1, mx1;
        mn1 = *(left2.begin());
        auto it1 = left1.end();
        it1--;
        mx1 = *(it1);
        mn2 = *(right2.begin());
        auto it2 = right1.end();
        it2--;
        mx2 = *(it2);
        int locans = max(0, mn1 - mx1 + 1) + max(0, mn2 - mx2 + 1);
        if (locans > ans) {
            ans = locans;
        }
        mx = max(ans, mx);
    }
    cout << mx;
    return 0;
}


Measured memory_bytes: 10368