#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using dd = double;
using vdd = std::vector<dd>;
using vvdd = std::vector<vdd>;
using vvvdd = std::vector<vvdd>;

constexpr ll INF = 1LL << 60;
constexpr dd EPS = 1e-11;

typedef std::numeric_limits< double > dbl;

//cin,cout高速化のおまじない＋桁数指定
struct Fast{
	Fast(){
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
	}
} fast;

#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, N-1)
#define DEPS(i, E, S) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, N-1, 0)
#define EACH(e, v) for (auto&& e : v)

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T> &v, ll S, ll E){ T m=v[S]; REPS(i, S, E)chmax(m, v[i]); return m; }//v[S]～v[E]の最大値
template<class T> inline T MinE(vector<T> &v, ll S, ll E){ T m=v[S]; REPS(i, S, E)chmin(m, v[i]); return m; }//v[S]～v[E]の最小値
template<class T> inline T MaxE(vector<T> &v, ll N) { return MaxE(v, 0, N - 1); } //先頭N個中の最大値
template<class T> inline T MinE(vector<T> &v, ll N) { return MinE(v, 0, N - 1); }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v, (ll)v.size()); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v, (ll)v.size()); }
template<class T> inline ll MaxI(vector<T> &v, ll S, ll E){ ll m=S; REPS(i, S, E){ if (v[i]>v[m])m=i; }return m; }
template<class T> inline ll MinI(vector<T> &v, ll S, ll E){ ll m=S; REPS(i, S, E){ if (v[i]<v[m])m=i; }return m; }
template<class T> inline ll MaxI(vector<T> &v, ll N) { return MaxI(v, 0, N - 1); }
template<class T> inline ll MinI(vector<T> &v, ll N) { return MinI(v, 0, N - 1); }
template<class T> inline ll MaxI(vector<T> &v) { return MaxI(v, (ll)v.size()); }
template<class T> inline ll MinI(vector<T> &v) { return MinI(v, (ll)v.size()); }
template<class T> inline T Sum(vector<T> &v, ll S, ll E){ T s=v[S]; REPS(i, S+1, E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v, ll N) { return Sum(v, 0, N - 1); }
template<class T> inline T Sum(vector<T> &v) { return Sum(v, v.size()); }

//剰余計算用クラス
constexpr ll MOD = (ll)(1e9 + 7); // 998244353L;
template<int mod> struct Modll{
	ll val;
	Modll(ll v = 0): val(v % mod){
		if (val < 0) val += mod;
	}
	Modll operator - () { return -val; }
	Modll operator + (const Modll &b) const {return val + b.val;}
	Modll operator - (const Modll &b) const {return val - b.val;}
	Modll operator * (const Modll &b) const {return val * b.val;}
	Modll operator / (const Modll &b) const {return Modll(*this) /= b; }
	Modll operator + (ll b) const { return *this + Modll(b); }
	Modll operator - (ll b) const { return *this - Modll(b); }
	Modll operator * (ll b) const { return *this * Modll(b); }
	friend Modll<mod> operator + (ll a, const Modll<mod> &b) { return b + a; }
	friend Modll<mod> operator - (ll a, const Modll<mod> &b) { return -b + a; }
	friend Modll<mod> operator * (ll a, const Modll<mod> &b) { return b * a; }
	Modll &operator += (const Modll &b) { val=(val+b.val)%mod; return *this; }
	Modll &operator -= (const Modll &b) { val=(val+mod-b.val)%mod; return *this; }
	Modll &operator *= (const Modll &b) { val=(val*b.val)%mod; return *this; }
	Modll &operator /= (const Modll &b) {
		ll c=b.val, d=mod, u=1, v=0;
		while (d){
			ll t = c / d;
			c -= t * d; swap(c, d);
			u -= t * v; swap(u, v);
		}
		val = val * u % mod;
		if (val < 0) val += mod;
		return *this;
	}
	Modll &operator += (ll b) { return *this += Modll(b); }
	Modll &operator -= (ll b) { return *this -= Modll(b); }
	Modll &operator *= (ll b) { return *this *= Modll(b); }
	Modll &operator /= (ll b) { return *this /= Modll(b); }
	bool operator == (const Modll &b) { return val == b.val; }
	bool operator != (const Modll &b) { return val != b.val; }
	bool operator == (ll b) { return *this == Modll(b); }
	bool operator != (ll b) { return *this != Modll(b); }
	friend bool operator == (ll a, const Modll<mod> &b) { return Modll<mod>(a) == b.val; }
	friend bool operator != (ll a, const Modll<mod> &b) { return Modll<mod>(a) != b.val; }
	friend ostream &operator << (ostream &os, const Modll<mod> &a) { return os << a.val; }
	friend istream &operator >> (istream &is, const Modll<mod> &a) { return is >> a.val; }
	Modll pow(ll n){
		if (n == 0) return 1;
		auto b = pow(n / 2);
		return (n%2 == 1) ? b*b*val : b*b;
	}
};
using modll = Modll<MOD>;

template<class T> inline T SumMOD(vector<T> &v, ll S, ll E){ T s=v[S]; REPS(i, S+1, E)s=(s+v[i])%MOD; return s; }
template<class T> inline T SumMOD(vector<T> &v, ll N) { return SumMOD(v, 0, N - 1); }
template<class T> inline T SumMOD(vector<T> &v) { return SumMOD(v, v.size()); }

inline ll in() { ll x; cin >> x; return x; }
inline double inD() { double x; cin >> x; return x; }
inline string inS() { string x; cin >> x; return std::move(x); }
template<class T=ll> inline vector<T> in_v(ll N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v); }
inline void To0origin(vll &v) { EACH(e, v) e--; }

ll N;
std::vector<pair<ll, ll>> LR;


int main()
{
	cin >> N;
	REP(i, N){
		ll L, R;
		cin >> L >> R;
		LR.emplace_back(L, R);
	}

	///// どちらかのコンテストが1問の時
	vll LVec,RVec;
	EACH(e, LR){
		LVec.push_back(e.first);
		RVec.push_back(e.second);
	}
	std::sort(LVec.begin(), LVec.end());
	std::sort(RVec.begin(), RVec.end());
	ll Lmax1 = LVec[N-1];
	ll Lmax2 = LVec[N-2];
	ll Rmin1 = RVec[0];
	ll Rmin2 = RVec[1];

	ll tanoMax = 0;
	EACH(e, LR){
		ll L = e.first;
		ll R = e.second;
		ll Lmax = (L != Lmax1) ? Lmax1 : Lmax2;
		ll Rmin = (R != Rmin1) ? Rmin1 : Rmin2;
		chmax(tanoMax, (R-L+1) + std::max(Rmin-Lmax+1, 0LL));
	}

	///// 両方のコンテストが2問以上の時
	std::sort(LR.begin(), LR.end(),
		[](auto &a, auto &b) {return a > b; }
	);
#if 0
	//RminよりLが大きいLRが、1つ以下なら終了
	if (LR[1].first <= Rmin1){
		cout << tanoMax << '\n';
		return 0;
	}
#endif

	ll rightConL=0, rightConR=INF;
	REP(i,N-2){
		ll L = LR[i].first;
		ll R = LR[i].second;
		if (R == Rmin1) break;

		chmax(rightConL, L);
		chmin(rightConR, R);

		chmax(tanoMax,
			std::max((Rmin1 - LR[i+1].first + 1), 0LL) +
			std::max((rightConR - rightConL + 1), 0LL)
		);
	}
	cout << tanoMax << '\n';

	return 0;
}


Measured memory_bytes: 4720