#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll func(vector<P> lr,ll n) {
	sort(all(lr), [&](P x, P y) {
		return x.second - x.first < y.second - y.first;
		});
	/*
	for (auto i : lr) {
		cout << i.first << " " << i.second<<endl;
	}
	*/

	P con1;
	P con2;

	con1.first = lr[n - 1].first;
	con1.second = lr[n - 1].second;
	ll loss_i = 0;

	ll loss = 0;
	for (int i = 0; i < n - 1; i++) {
		ll loss2 = 0;
		if (lr[i].first >= con1.first && lr[i].second <= con1.second) {
			loss2 = lr[i].first - con1.first + con1.second - lr[i].second;
		}
		else if (lr[i].first <= con1.first && lr[i].second <= con1.second) {
			loss2 += con1.second - lr[i].second;
		}
		else if (lr[i].first >= con1.first && lr[i].second >= con1.second) {
			loss2 = lr[i].first - con1.first;
		}
		else {
			loss2 = con1.second - con1.first;
		}

		if (loss <= loss2) {
			loss = loss2;
			con2.second = lr[i].second;
			con2.first = lr[i].first;
			loss_i = i;
		}
	}

	//cout << con1.first << " " << con1.second << endl;
	//cout << con2.first << " " << con2.second << endl;

	bool flag = true;

	for (int i = 0; i < n - 1; i++) {
		if (i != loss_i) {
			P con1_2 = con1;
			P con2_2 = con2;


			chmin(con1_2.second, lr[i].second);
			chmin(con2_2.second, lr[i].second);
			chmax(con1_2.first, lr[i].first);
			chmax(con2_2.first, lr[i].first);

			ll sum1 = 0;
			chmax(sum1, con1_2.second - con1_2.first + 1);
			ll sum2 = 0;
			chmax(sum2, con2_2.second - con2_2.first + 1);
			if (sum1 + con2.second - con2.first + 1
	> con1.second - con1.first + 1 + sum2) {
				con1 = con1_2;
				if (sum1 == 0) {
					flag = false;
					break;
				}
			}
			else {
				con2 = con2_2;
				if (sum2 == 0) {
					flag = false;
					break;
				}
			}
		}
	}

	P excon2 = make_pair(0, INF);

	for (auto i : lr) {
		if (lr[n - 1] != i) {
			chmax(excon2.first, i.first);
			chmin(excon2.second, i.second);
		}
	}

	ll exsum = 0;
	chmax(exsum, excon2.second - excon2.first);



	if (con1.second - con1.first + con2.second - con2.first + 2 < lr[n - 1].second - lr[n - 1].first + 1 + exsum) {
		flag = false;
	}
	if (flag) {
		return con1.second - con1.first + con2.second - con2.first + 2;
	}
	else {
		return lr[n - 1].second - lr[n - 1].first + 1 + exsum;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	ll n;
	cin >> n;
	vector<P> lr(n);
	REP(i, n) {
		cin >> lr[i].first >> lr[i].second;
	}
	sort(all(lr), [&](P x, P y) {
		if (x.first == y.first) return x.second > y.second;
			return x.first < y.first;
		});

	vector<P> l(n);
	vector<P> r(n);

	l[0] = lr[0];

	for (int i = 1; i < n;i++) {
		l[i] = l[i - 1];
		chmax(l[i].first, lr[i].first);
		chmin(l[i].second, lr[i].second);
	}

	r[n - 1] = lr[n - 1];
	for (int i = n-2; i>=0; i--) {
		r[i] = r[i+1];
		chmax(r[i].first, lr[i].first);
		chmin(r[i].second, lr[i].second);
	}
	ll ans = 0;
	REP(i, n - 1) {
		ll sum = 0;
		if (l[i].second - l[i].first + 1 > 0)sum += l[i].second - l[i].first + 1;
		if (r[i + 1].second - r[i+1].first + 1 > 0)sum += r[i + 1].second - r[i+1].first + 1;
		chmax(ans, sum);
		//cout << i << ":" << sum << endl;
	}

	chmax(ans, func(lr,n));

	cout << ans << endl;




	return 0;
}

Measured memory_bytes: 6568