#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<P> v;
ll l[100100],r[100100];

bool comp(P a, P b){
	return ((a.first==b.first)?(a.second>b.second):(a.first<b.first));
}

int main(void){
	int n,i,p,q;
	ll ans,ml=-INFLL,mr=INFLL,m=-INFLL;
	bool flag = false;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> l[i] >> r[i]; --l[i];
		m = max(m,r[i]-l[i]);
		ml = max(ml,l[i]);
		mr = min(mr,r[i]);
	}
	ans = m + max(mr-ml,0ll);
	for(i=0; i<n; ++i){
		v.push_back(P(max(r[i]-ml,0ll),max(mr-l[i],0ll)));
	}
	sort(v.begin(),v.end(),comp);
	m = INFLL;
	for(i=0; i<n; ++i){
		if(i){
			ans = max(ans,m+v[i].first);
			// cout << m+v[i].first << endl;
		}
		m = min(m,v[i].second);
	}
	cout << ans << endl;
	return 0;
}
