#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
pair<int,int>p[100010];
int pl[100010],pr[100010],sl[100010],sr[100010],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d %d",&p[i].first,&p[i].second);
	sort(p+1,p+1+n);
	pl[0]=1,pr[0]=1000000000;
	for(int i=1;i<=n;++i)
	{
		pl[i]=p[i].first;
		pr[i]=min(p[i].second,pr[i-1]);
	}
	sl[n+1]=0,sr[n+1]=1000000000;
	for(int i=n;i;--i)
	{
		sl[i]=p[n].first;
		sr[i]=min(sr[i+1],p[i].second);
	}
	for(int i=1;i<n;++i)ans=max(ans,max(pr[i]-pl[i]+1,0)+max(sr[i+1]-sl[i+1]+1,0));
	for(int i=1;i<=n;++i)ans=max(ans,p[i].second-p[i].first+1+max(min(pr[i-1],sr[i+1])-max(pl[i-1],sl[i+1])+1,0));
	printf("%d",ans);
	return 0;
}