#include <bits/stdc++.h>

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1LL * MX * MX;

int n;
PII Intrv[N];
int pref[N], suf[N];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d %d", &Intrv[i].st, &Intrv[i].nd);
	sort(Intrv + 1, Intrv + n + 1);
	
	pref[0] = MX;
	for(int i = 1; i <= n; ++i)
		pref[i] = min(pref[i - 1], Intrv[i].nd);
	
	suf[n + 1] = MX;
	for(int i = n; i >= 1; --i)
		suf[i] = min(suf[i + 1], Intrv[i].nd);
	
	int ans = 0;
	for(int i = 1; i <= n; ++i){
		int Left = i == n ? Intrv[n - 1].st : Intrv[n].st;
		ans = max(ans, Intrv[i].nd - Intrv[i].st + 1 + max(0, min(suf[i + 1], pref[i - 1]) - Left + 1));
	}
	
	for(int i = 1; i < n; ++i)
		ans = max(ans, max(0, pref[i] - Intrv[i].st + 1) + max(0, suf[i + 1] - Intrv[n].st + 1));
	printf("%d\n", ans);
	return 0;
}