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

typedef long long ll;
 
const int INF= 1001001001;
const ll LINF= 1e18;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

int main(){
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	int min_b = *min_element(b.begin(),b.end());
	int max_a = *max_element(a.begin(),a.end());
	int ans = 0;
	vector<pair<int,int>> p(n);
	for(int i = 0; i < n; i++){
		p[i] = make_pair(min_b-a[i]+1,b[i]-max_a+1);
	}
	sort(p.begin(),p.end());
	int m2 = 1e9;
	for(int i = 0; i < n-1; i++){
		m2 = min(m2,p[i].second);
		ans = max(ans,p[i+1].first + m2);
	}
	for(int i = 0; i < n; i++){
		int cur = b[i] - a[i] + 1;
		cur += max(0,min_b - max_a + 1);
		ans = max(ans,cur);
	}
	cout << ans << "\n";
	return 0;
}