#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N;
	vector<pair<long long, long long> > V;
	cin >> N;
	V.resize(N);
	for (int i = 0; i < N; i++) cin >> V[i].first >> V[i].second, V[i].second++;
	sort(V.begin(), V.end());
	long long LMAX = V[V.size() - 1].first, RMIN = 1000000000000, LenMax = 0;
	for (int i = 0; i < N; i++) {
		LenMax = max(LenMax, V[i].second - V[i].first);
		RMIN = min(RMIN, V[i].second);
	}
	long long ANS = LenMax + max(0LL, RMIN - LMAX);
	long long CurRMIN = 1000000000000;
	for (int i = N - 1; i >= 1; i--) {
		CurRMIN = min(CurRMIN, V[i].second);
		ANS = max(ANS, max(0LL, CurRMIN - LMAX) + max(0LL, RMIN - V[i - 1].first));
	}
	cout << ANS << endl;
}