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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 1e5 + 5;
pair<int, int> arr[N];
int pre[N], suf[N];

int len(int l, int r)
{
	if (l > r) return 0;
	return r - l + 1;
}

int main()
{
	int n = read();
	for (int i = 1; i <= n; ++i) arr[i] = {read(), read()};
	sort(arr + 1, arr + n + 1);
	
	pre[0] = suf[n + 1] = 1e9;
	for (int i = 1; i <= n; ++i) pre[i] = min(pre[i - 1], arr[i].second);
	for (int i = n; i >= 1; --i) suf[i] = min(suf[i + 1], arr[i].second);
	
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = max(ans, len(arr[i].first, arr[i].second) 
					 + len(arr[n].first, min(pre[i], suf[i])));
	for (int i = 1; i < n; ++i)
		ans = max(ans, len(arr[i].first, pre[i])
					 + len(arr[n].first, suf[i + 1]));
	printf("%d\n", ans);
	return 0;
}
