#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int INF = 2e9 + 6;
vector<ii> useless;
vector<ii> all, good;
map<int, int> Lpoint, Rpoint;
int n;

int joy(int l, int r) {
    return max(0, r - l + 1);
}

ii merge(int L1, int R1, int L2, int R2) {
    return ii(max(L1, L2), min(R1, R2));
}

int max_useless() {
    int best = 0;
    for (const auto &each : useless) best = max(best, joy(each.first, each.second));
    return best;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    fori(i, 0, n) {
        int l, r;
        cin >> l >> r;
        all.emplace_back(l, r);
        if (Lpoint.count(l)) {
            if (Lpoint[l] <= r) {
                useless.emplace_back(l, r);
            }
            else {
                useless.emplace_back(l, Lpoint[l]);
                Lpoint[l] = r;
            }
        }
        else {
            Lpoint[l] = r;
        }
        if (Rpoint.count(r)) {
            if (Rpoint[r] >= l) {
                useless.emplace_back(l, r);
            }
            else {
                useless.emplace_back(Rpoint[r], r);
                Rpoint[r] = l;
            }
        }
        else {
            Rpoint[r] = l;
        }
    }
    for (const auto &each : Lpoint) {
        if (Rpoint[each.second] == each.first) {
            good.emplace_back(each.first, each.second);
        }
    }
    vector<ii> x_pref(n);
    vector<ii> x_suf(n);
    int Lmax = -INF, Rmin = INF;
    fori(i, 0, n) {
        Lmax = max(Lmax, all[i].first);
        Rmin = min(Rmin, all[i].second);
        x_pref[i] = ii(Lmax, Rmin); 
    }
    Lmax = -INF, Rmin = INF;
    ford(i, n - 1, 0) {
        Lmax = max(Lmax, all[i].first);
        Rmin = min(Rmin, all[i].second);
        x_suf[i] = ii(Lmax, Rmin); 
    }
    int ans = 0;
    fori(i, 0, n) {
        ii Lside = ii(-INF, INF);
        ii Rside = ii(-INF, INF);
        if(i != 0) Lside = x_pref[i - 1];
        if(i != n - 1) Rside = x_suf[i + 1];
        ii m = merge(Lside.first, Lside.second, Rside.first, Rside.second);
        ans = max(ans, joy(all[i].first, all[i].second) + joy(m.first, m.second));
    }
    if ((int) good.size() == 1) {
        ans = max(ans, good[0].second - good[0].first + 1 + max_useless());
    }
    else {
        int last_joy = joy(good.back().first, good.back().second);
        Lmax = -INF, Rmin = INF;
        fori(i, 0, good.size() - 1) {
            Lmax = max(Lmax, good[i].first);
            Rmin = min(Rmin, good[i].second);
        }
        int pref_joy = joy(Lmax, Rmin);
        ans = max(ans, last_joy + pref_joy);
        vector<ii> by_R;
        fori(i, 0, good.size()) by_R.push_back(good[i]);
        sort(by_R.begin(), by_R.end(), [] (ii lhs, ii rhs) {
            return lhs.second < rhs.second;
        });
        int last_index = 0;
        fori(i, 0, by_R.size()) {
            if(by_R[i] == good.back()) {
                last_index = i;
            }
        }
        vector<int> pref_price(by_R.size(), 0);
        Lmax = -INF, Rmin = INF;
        fori(i, 0, by_R.size()) {
            Lmax = max(Lmax, by_R[i].first);
            Rmin = min(Rmin, by_R[i].second);
            pref_price[i] = joy(Lmax, Rmin);
        }
        int last_L = good.back().first;
        ford(i, last_index, 0) {
           int cur_R = by_R[i].second; 
           int cur_joy = joy(last_L, cur_R);
           int other_joy = 0;
           if(i == 0) {
                other_joy = max_useless();
           }
           else {
                other_joy = pref_price[i - 1];
           }
           ans = max(ans, cur_joy + other_joy);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 14324