#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

int find(int n, const vector<pii>& segments) {
	vector<int> prefL(n), prefR(n);
	prefL[0] = segments[0].first;
	prefR[0] = segments[0].second;

	for(int i = 1; i < n; ++i) {
		prefL[i] = max(prefL[i - 1], segments[i].first);
		prefR[i] = min(prefR[i - 1], segments[i].second);
	}

	vector<int> suffL(n), suffR(n);
	suffL[n - 1] = segments[n - 1].first;
	suffR[n - 1] = segments[n - 1].second;

	for(int i = n - 2; i >= 0; --i) {
		suffL[i] = max(suffL[i + 1], segments[i].first);
		suffR[i] = min(suffR[i + 1], segments[i].second);
	}

	int answ = 0;

	for(int m = 0; m < n - 1; ++m) {
		int local = 0;
		local += max(0, prefR[m] - prefL[m] + 1);
		local += max(0, suffR[m + 1] - suffL[m + 1] + 1);

		//DBG(m); DBG(local);
		answ = max(answ, local);
	}

	return answ;
}

bool compR(const pii& lhs, const pii& rhs) {
	if(lhs.second != rhs.second) {
		return lhs.second < rhs.second;
	} else {
		return lhs.first < rhs.first;
	}
}

bool comp_len_L(const pii& lhs, const pii& rhs) {
	if(lhs.second - lhs.first != rhs.second - rhs.first) {
		return lhs.second - lhs.first < rhs.second - rhs.first;
	} else {
		return lhs < rhs;
	}
}

bool comp_len_R(const pii& lhs, const pii& rhs) {
	if(lhs.second - lhs.first != rhs.second - rhs.first) {
		return lhs.second - lhs.first < rhs.second - rhs.first;
	} else {
		return compR(lhs, rhs);
	}
}

void solve() {
	int n = fetch<int>();
	vector<pii> segments(n);

	for(auto& elem: segments) {
		cin >> elem.first >> elem.second;
	}

	int total = 0; //find(n, segments);

	for(auto& seg: segments) {
		total = max(total, seg.second - seg.first + 1);
	}

	sort(segments.begin(), segments.end());
	total = max(total, find(n, segments));

	sort(segments.begin(), segments.end(), compR);
	total = max(total, find(n, segments));

	sort(segments.begin(), segments.end(), comp_len_L);
	total = max(total, find(n, segments));

	sort(segments.begin(), segments.end(), comp_len_R);
	total = max(total, find(n, segments));

	/*for(int t = 0; t < 60; ++t) {
		shuffle(segments.begin(), segments.end(), _g);
		total = max(total, find(n, segments));
	}*/

	cout << total << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 2656