/*
 * @Author: RBQRBQ
 * @Date: 2020-04-05 15:08:15
 * @LastEditors: RBQRBQ
 * @LastEditTime: 2020-04-05 19:16:50
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll,ll> pii;
namespace IO{
    template<typename T>inline void read(T &x){
        x=0;ll f=1;char ch=getchar();
        while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
        while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
        x=x*f;
    }
}
using namespace IO;
vector<pii> pp;
vector<pii> T;
ll mxL,minR,mxR,minL;


int main()
{
    int N;
    cin>>N;
    mxL=mxR=-1;
    minL=minR=10000000000ll;
    int P,Q;
    for(int i=1;i<=N;i++)
    {
        ll x,y;
        read(x),read(y);
        y++;
        pp.push_back(make_pair(x,y));
        if(x>mxL)
        {
            mxL=x;
            P=i;
        }
        if(minR>y)
        {
            minR=y;
            Q=i;
        }
    }
    ll ans1=0,ans2=0;
    minL=0;
    for(int i=1;i<=N;i++)
    {
            minL=max(minL,pp[i-1].second-pp[i-1].first);
    }

    ans1=max((minL),0ll)+max((minR-mxL),0ll);

    int ca=1;
    for(auto p:pp)
    {
        if(ca!=P&&ca!=Q)
        T.push_back(make_pair(max(p.second-mxL,0ll),max(minR-p.first,0ll)));
        ca++;
    }
    sort(T.begin(),T.end());
    ll P1=pp[P-1].second-pp[P-1].first;
    ll Q1=pp[Q-1].second-pp[Q-1].first;
    ll x1=0,x2=Q1;
    // for(auto p:T)
    // {
    //     cout<<p.first<<" "<<p.second<<endl;
    // }
    for(int i=0;i<T.size();i++)
    {
        
        x1=min(T[i].first,P1);
        ans2=max(ans2,x1+x2);
        x2=min(T[i].second,x2);
    }
    ans2=max(ans2,P1+x2);
    cout<<max(ans1,ans2);

}
/* ALDS1_5_D: The number of inversions */

#include <iostream>
#include <cmath>

const int MAX_VALUE = pow(10, 9);

long long count_and_merge(int A[], int left, int mid, int right) {
    int n_left  = mid - left;
    int n_right = right - mid;
    int *L = new int[n_left + 1];
    int *R = new int[n_right + 1];

    for (int i = 0; i < n_left; i++)
        L[i] = A[left + i];
    for (int i = 0; i < n_right; i++)
        R[i] = A[mid + i];
    L[n_left] = R[n_right] = MAX_VALUE + 1;

    int i_l = 0, i_r = 0;
    long long n_invs = 0;
    int n_left_remains = n_left;
    for (int i_a = left; i_a < right; i_a++) {
        if (L[i_l] <= R[i_r]) {
            A[i_a] = L[ i_l++ ];
            n_left_remains--;
        } else {
            A[i_a] = R[ i_r++ ];
            n_invs += n_left_remains;
        }
    }
    return n_invs;
}

long long merge_sort(int A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        long long n_invs = 0;
        n_invs += merge_sort(A, left, mid);
        n_invs += merge_sort(A, mid, right);
        n_invs += count_and_merge(A, left, mid, right);
        return n_invs;
    }
    return 0;
}

long long count_inversions(int n, int A[]) {
    return merge_sort(A, 0, n);
}

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;
    int *A = new int[n];
    for (int i = 0; i < n; i++)
        std::cin >> A[i];

    long long n_invs = count_inversions(n, A);
    std::cout << n_invs << std::endl;
    return 0;
}