#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 100100

ll n;
pii a[MAX];

pair<bool,pii> get_intersection(vector<pii>& b){
	pii current = b[0];
	for(pii c:b){
		if(c.fi>current.se || c.se<current.fi) return {false,{1,1}};
		current.fi = max(current.fi,c.fi);
		current.se = min(current.se,c.se);
		if(current.fi>current.se) return {false,{1,1}};
	}
	return {true,current};
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n;
	ll max_len = 0;
	For(i,0,n) {
		cin>>a[i].fi>>a[i].se;
		max_len = max(max_len,(a[i].se-a[i].fi+1));
	}
	sort(a,a+n,[](const pii& a,const pii& b)->bool{
		if(a.se==b.se){
			return a.fi>b.fi;
		}
		return a.se<b.se;
	});

	vector<pii> b;
	For(i,0,n){
		if(a[i].fi>a[0].se) b.pb(a[i]);
	}

	if(b.size()==0){
		vector<pii> middle;
		For(i,0,n){
			if(a[i].fi>=a[0].fi && a[i].fi<=a[0].se){
				middle.pb(a[i]);
			}
		}

		if(middle.size()==1){
			ll max_len = 0;
			For(i,1,n){
				max_len = max(max_len,a[i].se-a[i].fi+1);
			}
			cout<<max_len+(a[0].se-a[0].fi+1)<<endl;
			return 0;
		}else{
			sort(middle.begin(),middle.end());
			pii c = middle.back();

			ll ans = -100;
			Fod(i,middle.size()-1,0){
				pii current = middle[i];
				current.fi = current.fi;
				current.se = a[0].se;


				ans = max(ans,(current.se-current.fi+1)+(c.se-c.fi+1));
				if(middle[i].se<c.fi) break;
				else{
					c.se = middle[i].se;
				}
			}
			assert(ans>=0);

			vector<pii> b;
			ll index = -1;
			For(i,0,n){
				if(a[i].se-a[i].fi+1==max_len) index=i;
			}
			For(i,0,n) if(i!=index) {
				b.pb(a[i]);
			}
			pair<bool,pii> get = get_intersection(b);
			if(get.fi){
				pii c = get.se;
				ans = max(ans,(c.se-c.fi+1)+(a[index].se-a[index].fi+1));
			}
			cout<<ans<<endl;
		}
	}else{
		pair<bool,pii> get = get_intersection(b);

		if(!get.fi){
			cout<<max_len<<endl;
			return 0;
		}else{
			pii c = get.se;
			vector<pii> middle;
			For(i,0,n){
				if(a[i].fi>=a[0].fi && a[i].fi<=a[0].se){
					if(a[i].se>=c.se) continue;
					middle.pb(a[i]);
				}
			}

			if(middle.size()==1){
				cout<<max((a[0].se-a[0].fi+1)+(c.se-c.fi+1),max_len)<<endl;
				return 0;
			}else{
				sort(middle.begin(),middle.end());


				ll ans = -100;
				Fod(i,middle.size(),0){
					pii current = middle[i];
					current.fi = current.fi;
					current.se = a[0].se;


					ans = max(ans,(current.se-current.fi+1)+(c.se-c.fi+1));
					if(middle[i].se<c.fi) break;
					else{
						c.se = middle[i].se;
					}
				}
				assert(ans>=0);
				ans = max(ans,max_len);
				cout<<ans<<endl;
			}

		}
	}


























	
}

Measured memory_bytes: 6512