#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

pll intersection( pll ans, pll now )
{
    ll mn = ans.F, mx = ans.S;
    ll left = now.F, right = now.S;

    if( left < mn )
    {
        swap(left,mn);
        swap(right,mx);
    }
    if( left <= mx )
    {
        mx = min(mx, right);
        mn = max(mn, left);
        ans = {mn,mx};
    }
    else
        ans = {0,-1};

    return ans;
}


int main() 
{
    fastio();

    int n;
    cin>>n;
    vector<pll>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i].F>>v[i].S;
    }
    sort(all(v));


    vector<pll>pref(n+1,{0,-1}),suff(n+1,{0,-1});
    ll mn = -INF, mx = INF;
    for(int i=0;i<n;i++)
    {
        ll left = v[i].F, right = v[i].S;
        if( left <= mx )
        {
            mx = min(mx, right);
            mn = max(mn, left);
            pref[i] = {mn,mx};
        }
        else
            break;
    }

    mn = -INF, mx = INF;
    for(int i=n-1;i>=0;i--)
    {
        ll left = v[i].F, right = v[i].S;
        if( left < mn )
        {
            swap(left,mn);
            swap(right,mx);
        }
        if( left <= mx )
        {
            mx = min(mx, right);
            mn = max(mn, left);
            suff[i] = {mn,mx};
        }
        else
            break;
    }

    ll ans = 0;
    for(int i=0;i<n-1;i++)
    {
        ans = max(ans, (pref[i].S-pref[i].F+1)+(suff[i+1].S-suff[i+1].F+1) );
    }

    for(int i=0;i<n;i++)
    {
        pll inter = {-INF,INF};
        ll tans = v[i].S - v[i].F + 1;
        if( i-1 >= 0 )
            inter = intersection(inter, pref[i-1]);
        if( i+1 < n )
            inter = intersection(inter, suff[i+1]);
        ans = max(ans, tans + inter.S - inter.F + 1 );
    }
    cout<<ans,nl;
    return 0;
}

Measured memory_bytes: 4992