#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int, int> > LR(N);
    for (auto & lr : LR) {
        cin >> lr.first >> lr.second;
    }
    sort(LR.begin(), LR.end());
    vector<int> MIN(N), MINR(N);
    MIN[0] = LR[0].second;
    MINR[N-1] = LR[N-1].second;
    for (int i = 1; i < N; ++i) {
        MIN[i] = min(MIN[i-1], LR[i].second);
        MINR[N-1-i] = min(MINR[N-i], LR[N-1-i].second);
    }
    int ans = 0;
    for (int i = 1; i < N; ++i) {
        ans = max(ans, max(0, MIN[i-1]-LR[i-1].first+1) + max(0, MINR[i]-LR[N-1].first+1));
    }
    for (int i = 1; i < N-1; ++i) {
        ans = max(ans, max(0, MIN[N-1]-LR[N-1].first+1) + max(0, LR[i].second-LR[i].first+1));
    }
    printf("%d\n", ans);
    return 0;
}
