//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;
 
    vl L(n), R(n);
    ll p = 0, q = 0;  // L[p]はLの最大値で、R[q]はRの最小値
    ll MAXL = 0, MINR = INF;
    rep(i, n) {
        cin >> L[i] >> R[i];
        R[i]++;
        if(MAXL < L[i]) {
            MAXL = L[i];
            p = i;
        }
        if(MINR > R[i]) {
            MINR = R[i];
            q = i;
        }
    }
 
    ll ans = 0;
    // 区間pと区間qを同じ集合に入れる場合
    rep(i, n) {
        if(i == p || i == q) {
            continue;
        }
        chmax(ans, max(0LL, R[q] - L[p]) + R[i] - L[i]);
    }
 
    // 区間pと区間qを違う集合に入れる場合
    vector<pair<ll, ll>> c(n);
    rep(i, n) {
        ll a = max(0LL, R[i] - L[p]);
        ll b = max(0LL, R[q] - L[i]);
        c[i] = make_pair(a, -b);
    }
    sort(all(c));
    ll u = abs(c[0].second);
    exrep(i, 1, n-1) {
        chmax(ans, c[i].first + u);
        chmin(u, abs(c[i].second));
    }
 
    out(ans);
    re0;
}