#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int N=1e6+5;
int n,pre[N],suf[N];
struct node{
	int x,y;
}a[N];
bool cmp(node a,node b)
{
	if(a.x==b.x)return a.y<b.y;
	return a.x<b.x;
}
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();
	int mi=1e18,ma=0;
	for(int i=1;i<=n;i++)
	{
		a[i].x=read();a[i].y=read()+1;
		mi=min(mi,a[i].y);
		ma=max(ma,a[i].x);
	}
	int ans=max(mi-ma,0ll)+a[1].y-a[1].x;
	for(int i=2;i<=n;i++)ans=max(ans,max(mi-ma,0ll)+a[i].y-a[i].x);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)pre[i]=max(pre[i-1],a[i].x);
	suf[n+1]=1e18;
	for(int i=n;i;i--)suf[i]=min(suf[i+1],a[i].y);
	for(int i=1;i<n;i++)
		ans=max(ans,max(mi-pre[i],0ll)+max(suf[i+1]-ma,0ll));
	cout<<ans;
}