#include <iostream>
#include <cstdio>
#include <algorithm>
#define F first
#define S second

using namespace std;

typedef long long ll;

ll n;
pair<ll, ll> a[100005];
ll b[100005];
ll ans;
ll mx = 0, mn = 4e18;

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a[i].F, &a[i].S);
        a[i].S++;
    }
    sort(a, a + n);
    for(ll i = n - 1; i >= 1; i--)
    {
        mx = max(mx, a[i].F);
        mn = min(mn, a[i].S);
        b[i] = max(mn - mx, 0LL);
    }
    mx = 0, mn = 4e18;
    for(ll i = 0; i < n - 1; i++)
    {
        mx = max(mx, a[i].F);
        mn = min(mn, a[i].S);
        ans = max(ans, b[i + 1] + max(mn - mx, 0LL));
    }
    ll mlen=0LL;
    for(ll i = 0; i < n; i++)
    {
        mx = max(mx, a[i].F);
        mn = min(mn, a[i].S);
        mlen = max(mlen, a[i].S - a[i].F);
    }
	ans = max(ans, mlen + max(0LL, mn - mx));
    printf("%lld", ans);
    return 0;
}