#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

bool cmp(const PLL& a, const PLL& b){
    LL al,ar,bl,br;
    tie(al,ar) = a;
    tie(bl,br) = b;
    if(ar < br) return true;
    if(ar == br){
        return al < bl;
    }
    return false;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    vector<PLL> lr;
    int pi = -1, qi = -1;
    LL maxl = -1, minr = LINF;
    LL ldif = 0;
    REP(i,N){
        LL l,r; cin >> l >> r;
        r++;
        lr.eb(l,r);
        if(chmax(maxl,l)) pi = i;
        if(chmin(minr,r)) qi = i;
    }

    if(pi == qi){
        LL li,ri;
        tie(li,ri) = lr[pi];

        REP(i,N){
            if(i == pi) continue;
            LL l,r;
            tie(l,r) = lr[i];
            chmax(ldif, r-l);
        }

        cout << ldif + (ri - li) << endl;
        return 0;
    }

    LL ans = 0;

    REP(i,N){
        if(i == pi or i == qi) continue;
        LL l,r;
        tie(l,r) = lr[i];
        chmax(ldif, r-l);
    }
    chmax(ans, ldif + max(0LL,minr - maxl));

    vector<PLL> lr2;
    REP(i,N){
        if(i == pi or i == qi) continue;
        lr2.eb(lr[i]);
    }
    sort(lr2.begin(),lr2.end(),cmp);
    VL accmax(N-1, lr[qi].first);
    VL accmin(N-1, lr[pi].second);
    REP(i,N-2){
        accmax[i+1] = max(accmax[i], lr2[i].first);
    }
    dump("d2")
    REP(i,N-2){
        accmin[i+1] = min(accmin[i], lr2[N-3-i].second);
    }

    //for(auto p : lr2){
    //    cout << p.first << " " << p.second << endl;
    //}
    //dump("accmax")
    //REP(i,N-1){
    //    cout << accmax[i] << endl;
    //}
    //dump("accmin")
    //REP(i,N-1){
    //    cout << accmin[i] << endl;
    //}


    REP(i,N-1){
        chmax(ans, max(0LL,minr-accmax[i]) + max(0LL, accmin[N-2-i]-maxl));
    }
    cout << ans << endl;

}

Measured memory_bytes: 4976