#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;


template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

using P=pair<ll,pair<ll,ll>>;
void solve(){
	ll n;
	cin>>n;
	vector<P>p(n);
	rep(i,n){
		cin>>p[i].second.first>>p[i].second.second;
		p[i].first=p[i].second.second-p[i].second.first;
	}
	sort(all(p));
	ll ans=0;
	vector<ll>val(n+1),rval(n+1);
	ll left=0,right=1e9;
	rep(i,n){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		val[i+1]=right-left+1;
	}
	left=0,right=1e9;
	for(int i=n-1;i>=0;--i){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		rval[i]=right-left+1;
	}
	REP(i,1,n){
		//cout<<val[i]<<" "<<rval[i]<<"\n";
		chmax(ans,max(val[i],0LL)+max(rval[i],0LL));
	}
	rep(i,n)p[i].first=0;
	sort(all(p));
	left=0,right=1e9;
	rep(i,n){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		val[i+1]=right-left+1;
	}
	left=0,right=1e9;
	for(int i=n-1;i>=0;--i){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		rval[i]=right-left+1;
	}
	REP(i,1,n){
		//cout<<val[i]<<" "<<rval[i]<<"\n";
		chmax(ans,max(val[i],0LL)+max(rval[i],0LL));
	}
	cout<<ans<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}