#include <utility>
#include <iostream>
#include <cmath>
#include <deque>
#include <string>
#include <time.h>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN (1<<20)
#define MOD 1000000007
#define N 1048576
ll n, x, k, z, m, pos, q, ans_v;
ll x1, p1, x2, p2;
vector<ll> g[300500], f;
pii a[100500];
multiset<pii> l1, r1;

ll pshe(ll x, ll y) {
    if (y - x >= 0) {
        return y - x + 1;
    }
    return 0;
}

int main() {
    cin >> n;
    ll ans = 0;
    ll maxl = -1, minr = MOD;
    ll L, R;
    ll l = 0, r = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i].X >> a[i].Y;
        ans = max(ans, a[i].Y - a[i].X + 1);
    }


    if (n == 2) {
        cout << a[0].Y - a[0].X + a[1].Y - a[1].X + 2 << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        if (a[i].X > maxl) {
            maxl = a[i].X;
            L = a[i].Y;
            l = i;
        }
        if (a[i].Y < minr) {
            minr = a[i].Y;
            R = a[i].X;
            r = i;
        }
    }
    ll minl = MOD, maxr = -1;
    ll L1 = 0, R1 = 0;
    for (int i = 0; i < n; i++) {
        if (a[i].X == maxl) {
            if (a[i].Y < minl) {
                minl = a[i].Y;
                L1 = i;
            }
        }
        if (a[i].Y == minr) {
            if (a[i].X > maxr) {
                maxr = a[i].X;
                R1 = i;
            }
        }
    }
    l = L1;
    r = R1;
    L = a[L1].Y;
    R = a[R1].X;
    if (l == r) {
        cout << ans + minr - maxl + 1 << endl;
        return 0;
    }
    ll to_add = 0;
    if (maxl <= minr) {
        ans = 0;
        to_add = minr - maxl + 1;
        for (int i = 0; i < n; i++) {
            a[i].Y -= minr - maxl + 1;
        }

        maxl = -1, minr = MOD;
        l = 0, r = 0;
        for (int i = 0; i < n; i++) {
            ans = max(ans, a[i].Y - a[i].X + 1);
        }
        for (int i = 0; i < n; i++) {
            if (a[i].X > maxl) {
                maxl = a[i].X;
                L = a[i].Y;
                l = i;
            }
            if (a[i].Y < minr) {
                minr = a[i].Y;
                R = a[i].X;
                r = i;
            }
        }
        minl = MOD, maxr = -1;
        L1 = 0, R1 = 0;
        for (int i = 0; i < n; i++) {
            if (a[i].X == maxl) {
                if (a[i].Y < minl) {
                    minl = a[i].Y;
                    L1 = i;
                }
            }
            if (a[i].Y == minr) {
                if (a[i].X > maxr) {
                    maxr = a[i].X;
                    R1 = i;
                }
            }
        }
        l = L1;
        r = R1;
        L = a[L1].Y;
        R = a[R1].X;
    }


    for (int i = 0; i < n; i++) {
        if (i == l || i == r) {
            continue;
        }
        r1.insert(mp(a[i].Y, a[i].X));
    }



    ans = max(ans, minr - R + 1 + pshe(maxl, min(L, (r1.begin())->first)));
    while (!r1.empty()) {
        auto it = r1.begin();
        ll x = it->first;
        ll y = it->second;
        r1.erase(it);
        l1.insert(mp(y, x));
        if (r1.empty()) {
            ans = max(ans, L - maxl + 1 + pshe(max(R, (prev(l1.end()))->first), minr));
            break;
        }
        ans = max(ans, pshe(maxl, min(L, (r1.begin())->first)) +
                       pshe(max(R, (prev(l1.end()))->first), minr));
        //cout << pshe(maxl, min(L, (r1.begin())->first)) << " " << pshe(max(R, (prev(l1.end()))->first), minr) << endl;
    }
    cout << ans + to_add * 2 << endl;



    return 0;
}

Measured memory_bytes: 15104