#include<algorithm>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
typedef pair<int, int> P;

P lr[100000];
int n, mr[100000];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d %d", &lr[i].first, &lr[i].second);
    sort(lr, lr + n);

    mr[n - 1] = lr[n - 1].second;
    for (int i = n - 2; i >= 0; i--) mr[i] = min(mr[i + 1], lr[i].second);
    set<int> s;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        int res = 0;
        if (s.empty()) res = max(lr[i].second - lr[i].first + 1, 0) +
            max(mr[i + 1] - lr[n - 1].first + 1, 0);
        else {
            res = max(*s.begin() - lr[i].first + 1, 0) +
                max(mr[i + 1] - lr[n - 1].first + 1, 0);
            res = max(res, max(lr[i].second - lr[i].first + 1, 0) +
                max(min(*s.begin(), mr[i + 1]) - lr[n - 1].first  + 1, 0));
        }
        s.emplace(lr[i].second);
        ans = max(ans, res);
    }
    printf("%d\n", ans);
    return 0;
} 
