#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using Pi = pair<int, int>;

int N;
vector<int>L, R;

int main()
{
	int C = 1000000000;
	cin >> N;
	L = vector<int>(N);
	R = vector<int>(N);
	
	auto Q = vector<Pi>(0);


	for (int i = 0; i < N; i++) {
		cin >> L[i];
		cin >> R[i];

		Q.push_back(make_pair(L[i],R[i]));
	}

	sort(Q.begin(), Q.end(), [](Pi const& l, Pi const& r) {
		if (l.first == r.first) {
			return l.second > r.second;
		}
		return l.first < r.first;
		});

	vector<int> rmin_ary(N);
	rmin_ary[0] = Q[0].second;
	for (int i = 1; i < N; i++) {
		rmin_ary[i] = min(rmin_ary[i-1],Q[i].second);
	}

	int ans = 0;

	int opp_r = C;
	int opp_l = 0;
	for (int i = N-1; i > 0; i--) {
		opp_r = min(opp_r,Q[i].second);
		opp_l = max(opp_l,Q[i].first);

		int fun1 = max(0,opp_r - opp_l + 1) + max(0,rmin_ary[i - 1] - Q[i - 1].first + 1);
		int fun2 = max(0, min(opp_r,rmin_ary[i - 1]) - opp_l + 1) + max(0, Q[i - 1].second - Q[i - 1].first + 1);
		int fun = max(fun1,fun2);
		ans = max(ans, fun);

	}

	cout << ans << endl;

	return 0;
}