#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=4e5+10;
int n,ans,mx,r[maxn],ll,rr;
struct oo{int l,r;}a[maxn],s[maxn];
bool cmp(oo a,oo b){return a.l==b.l?a.r<b.r:a.l>b.l;}
int main(){
    read(n);int lx=0,rx=n+1;a[n+1].r=1e9;
    for(rg int i=1;i<=n;i++){
	read(a[i].l),read(a[i].r),mx=max(mx,a[i].r-a[i].l+1);
	if(a[i].l>a[lx].l)lx=i;
	if(a[i].r<a[rx].r)rx=i;
    }
    ans=max(0,a[rx].r-a[lx].l+1)+mx;rr=a[rx].r,ll=a[lx].l;
    for(rg int i=1;i<=n;i++)s[i]=(oo){max(a[i].r-ll+1,0),max(rr-a[i].l+1,0)};
    sort(s+1,s+n+1,cmp);r[n+1]=1e9;
    for(rg int i=n;i;i--)r[i]=min(r[i+1],s[i].r);
    for(rg int i=1;i<n;i++)ans=max(ans,s[i].l+r[i+1]);
    printf("%d\n",ans);
}
