#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<pair<Int, Int>> LR(N);
        set<Int> appL;
        for (int i = 0; i < N; ++i) {
            cin >> LR[i].first >> LR[i].second;
            appL.insert(LR[i].first);
        }
        sort(all(LR));

        map<Int, Int> fL, fR, sL, sR;
        for (int i = 0; i < N; ++i) {
            fL[LR[i].first]++;
            fR[LR[i].second]++;
        }

        Int ans = 0;
        Int lR, lL; // lRは右の最大値(左サイドになる), lLは左の最小値(右サイドになる)
        {
            auto itL = fL.end();
            itL--;
            auto itR = fR.begin();
            ans = max(0ll, itR->first - itL->first);
//            if (ans > 0) {
//                lR = itL->first;
//                lL = itR->first;
//            }
        }
        //区間スケジューリング



        int idx = 0;
        for (auto e : appL) {
            while (idx < LR.size() && LR[idx].first == e) {
                Int l = LR[idx].first;
                Int r = LR[idx].second;
                idx++;
                fL[l]--;
                if (fL[l] == 0) fL.erase(l);
                fR[r]--;
                if (fR[r] == 0) fR.erase(r);

                sL[l]++;
                sR[r]++;


                if (fL.size()) {
                    auto itFL = fL.end();
                    itFL--;
                    auto itFR = fR.begin();

                    auto itSL = sL.end();
                    itSL--;
                    auto itSR = sR.begin();

                    Int fval = max(0ll, itFR->first - itFL->first + 1);
                    Int sval = max(0ll, itSR->first - itSL->first + 1);

                    Int tmp = fval + sval;
//                    cerr << tmp << endl;
                    chmax(ans, tmp);
                }
            }
        }

        map<Int, Int> tL, tR; //のこりもの
        for (int i = 0; i < N; ++i) {
            tL[LR[i].first]++;
            tR[LR[i].second]++;
        }

        for (int i = 0; i < N; ++i) {
            //del
            Int l = LR[i].first;
            Int r = LR[i].second;
            tL[l]--;
            if (tL[l] == 0) tL.erase(l);
            tR[r]--;
            if (tR[r] == 0) tR.erase(r);

            Int ftmp = r - l + 1;

            auto itL = tL.end();
            itL--;
            auto itR = tR.begin();
            Int stmp = max(0ll, itR->first - itL->first + 1);

            Int tmp = ftmp + stmp;
            chmax(ans, tmp);

            tL[l]++;
            tR[r]++;
        }

        cout << ans << endl;


    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    map<Int, Int> mp;
//    mp[-99]++;
//    mp[0]++;
//    mp[3]++;
//    mp[5]++;
//    mp[9]++;
//    auto it = mp.begin();
////    it--;
//    cout << it->first << endl;

    Solve().solve();


    return 0;
}


Measured memory_bytes: 31488