#include<bits/stdc++.h>
using namespace std;

const int N=100010;
struct interval{
	int l,r;
	bool operator<(const interval q)const{
		return r<q.r;
	}
}s[N];
int n;
int maxl[N],lb[N],rb[N];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d %d",&s[i].l,&s[i].r);
	sort(s+1,s+1+n);
	int firl=s[1].l;
	for(int i=n;i>=1;i--) maxl[i]=max(maxl[i+1],s[i].l);
	int now=2,ans=0;
	while(now<=n){
		int tmp=now;
		while(now<=n && s[now].r==s[now+1].r) now++;
		lb[tmp-1]=rb[now+1]=0;
		for(int i=tmp;i<=now;i++) lb[i]=max(lb[i-1],s[i].l);
		for(int i=now;i>=tmp;i--) rb[i]=max(rb[i+1],s[i].l);
		int op=0;
		for(int i=tmp;i<=now;i++){
			op=max(lb[i-1],max(rb[i+1],maxl[now+1]));
			ans=max(ans,max(s[1].r-min(max(firl,op),s[1].r+1)+1+s[i].r-s[i].l+1,s[1].r-firl+1+s[i].r-min(max(s[i].l,op),s[i].r+1)+1));
		}
		firl=min(max(firl,lb[now]),s[1].r+1);
		now++;
	}
	printf("%d\n",ans);
}