#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 112345
int l[N], r[N];
multiset<pii> lr, rl;
int pl[N], pr[N], ql[N], qr[N];

////////////////////////
// multiset<int> pl, pr, ql, qr;
// int cnt(){
// 	DEBUG("pl: "); for(int i : pl) DEBUG(" %d", i); DEBUG("\n");
// 	DEBUG("pr: "); for(int i : pr) DEBUG(" %d", i); DEBUG("\n");
// 	DEBUG("ql: "); for(int i : ql) DEBUG(" %d", i); DEBUG("\n");
// 	DEBUG("qr: "); for(int i : qr) DEBUG(" %d", i); DEBUG("\n");
// 	DEBUG("\n");
// 	if(pl.empty() || ql.empty()) return 0;
// 	return max( *pr.begin() - *pl.rbegin() + 1, 0) 
// 		+ max( *qr.begin() - *ql.rbegin() + 1, 0);
// }
////////////////////////

int main(){
	int n; scanf("%d", &n);
	int mxi = 0;
	REP(i, n){
		scanf("%d%d", l+i, r+i);
		lr.emplace(l[i], r[i]);
		rl.emplace(r[i], l[i]);
		if(r[mxi] - l[mxi] < r[i] - l[i]){
			mxi = i;
		}
	}
	int ans1;
	{
		int p = INT_MIN, q = INT_MAX;
		REP(i, n) if(i != mxi) LAR(p, l[i]), SML(q, r[i]);
		ans1 = r[mxi]-l[mxi]+1 + max( q-p+1, 0 );
	}
	DEBUG("ans1 = %d\n", ans1);
	int ans2;
	{
		pl[0] = ql[N-1] = INT_MIN;
		pr[0] = qr[N-1] = INT_MAX;
		while(lr.size() >= 1){
			auto rmin = rl.begin();
			auto lmax = lr.rbegin();
			int rminl, rminr, lmaxl, lmaxr;
			if(lmax->first <= rmin->first) break;
			DEBUG("rmin = (%d, %d), lmax = (%d, %d)\n", 
					rmin->second, rmin->first,
					lmax->first, lmax->second);

////////////////////////
//			// put rmin to p
//			pl.emplace(rminl = rmin -> second);
//			pr.emplace(rminr = rmin -> first);
//			// put lmax to q
//			ql.emplace(lmaxl = lmax -> first);
//			qr.emplace(lmaxr = lmax -> second);
////////////////////////

			// put rmin to p
			LAR(pl[0], rminl = rmin -> second);
			SML(pr[0], rminr = rmin -> first);
			// put lmax to q
			LAR(ql[N-1], lmaxl = lmax -> first);
			SML(qr[N-1], lmaxr = lmax -> second);

			rl.erase(rl.find(MP(lmaxr, lmaxl)));
			rl.erase(rl.find(MP(rminr, rminl)));
			lr.erase(lr.find(MP(lmaxl, lmaxr)));
			lr.erase(lr.find(MP(rminl, rminr)));
			
			DEBUG("Done erasing\n");
		}

		int m;
		{
			DEBUG("(%d, %d)\n", pl[0], pr[0]);
			int i = 1;
			for(auto &p : lr){
				DEBUG("(%d, %d) qr[%d]\n", p.first, p.second, i-1);
				pl[i] = ql[i-1] = p.first;
				pr[i] = qr[i-1] = p.second;
				i++;
			}
			m = i;
			DEBUG("(%d, %d)\n", ql[N-1], qr[N-1]);
			DEBUG("m = %d\n", m);
		}
		FOR(i, 1, m+1){
			LAR(pl[i], pl[i-1]);
			SML(pr[i], pr[i-1]);
		}
		ql[m-1] = ql[N-1];
		qr[m-1] = qr[N-1];
		for(int i = m-2; i >= 0; i--){
			LAR(ql[i], ql[i+1]);
			SML(qr[i], qr[i+1]);
		}
		ans2 = 0;
		REP(i, m){
			DEBUG("i=%d (%d, %d) + (%d, %d)\n", i, pl[i], pr[i], ql[i], qr[i]);
			LAR(ans2, max(pr[i] - pl[i] + 1, 0) + max(qr[i] - ql[i] + 1, 0));
		}

////////////////////////
//		for(auto &p : lr){
//			ql.emplace(p.first);
//			qr.emplace(p.second);
//		}
//		ans2 = cnt();
//		// DEBUG("current = %d\n", ans2);
//		for(auto &p : lr){
//			int x = p.first, y = p.second;
//			DEBUG("moving (%d, %d)\n", x, y);
//			ql.erase(ql.find(x));
//			qr.erase(qr.find(y));
//			pl.emplace(x);
//			pr.emplace(y);
//			LAR(ans2, cnt());
//		}
/////////////////////////
	}
	
	printf("%d\n", max(ans1, ans2));
}






Measured memory_bytes: 12160