/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class BTwoContests {
public:
	void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        vector<pair<int, int>> LR(N);
        REP(i,0,N) in >> LR[i].first >> LR[i].second;

        sort(all(LR), [](const pair<int, int> & a, const pair<int, int> & b) -> bool {
            return a.first < b.first || a.first == b.first && a.second > b.second;
        });

        int maxLR = 0;
        map<int, int> LFirst, RFirst;
        REP(i,0,N) {
            LFirst[LR[i].first]++;
            RFirst[LR[i].second]++;
            maxLR = max(maxLR, LR[i].second - LR[i].first + 1);
        }
        int maxLFirst = 0, minRFirst = INT_MAX, maxLSecond = 0, minRSecond = INT_MAX;
        int answer = 0;
        REP(i,0,N-1) {
            int L = LR[i].first;
            int R = LR[i].second;
//            debug(L);
//            debug(R);
            maxLSecond = max(maxLSecond, L);
            minRSecond = min(minRSecond, R);
            LFirst[L]--;
            if (LFirst[L] == 0) LFirst.erase(L);
            RFirst[R]--;
            if (RFirst[R] == 0) RFirst.erase(R);
            maxLFirst = LFirst.rbegin()->first;
            minRFirst = RFirst.begin()->first;
//            debug(maxLFirst);
//            debug(maxLSecond);
//            debug(minRFirst);
//            debug(minRSecond);

            answer = max(answer, max(0, minRFirst - maxLFirst + 1) + max(0, minRSecond - maxLSecond + 1));
        }

        sort(all(LR), [](const pair<int, int> & a, const pair<int, int> & b) -> bool {
            return a.second > b.second || a.second == b.second && a.first < b.first;
        });

        LFirst.clear();
        RFirst.clear();
        REP(i,0,N) {
            LFirst[LR[i].first]++;
            RFirst[LR[i].second]++;
        }
        maxLFirst = 0, minRFirst = INT_MAX, maxLSecond = 0, minRSecond = INT_MAX;
        REP(i,0,N) {
            int L = LR[i].first;
            int R = LR[i].second;
//            debug(L);
//            debug(R);
            maxLSecond = L;
            minRSecond = R;
            LFirst[L]--;
            if (LFirst[L] == 0) LFirst.erase(L);
            RFirst[R]--;
            if (RFirst[R] == 0) RFirst.erase(R);
            maxLFirst = LFirst.rbegin()->first;
            minRFirst = RFirst.begin()->first;
//            debug(maxLFirst);
//            debug(maxLSecond);
//            debug(minRFirst);
//            debug(minRSecond);

            answer = max(answer, max(0, minRFirst - maxLFirst + 1) + max(0, minRSecond - maxLSecond + 1));

            LFirst[L]++;
            RFirst[R]++;
        }

        out << max(answer, maxLR) << "\n";
	}
};


signed main() {
	BTwoContests solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 10368