#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rep2(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
template<typename T> void chkmax(T &x,T y){x=x>y?x:y;}
template<typename T> void chkmin(T &x,T y){x=x<y?x:y;}

struct wzy{
	int l,r;
}co[200010];
inline bool cmp(wzy a,wzy b){
	return a.l<b.l;
}
inline int d(int ll,int rr){
	return max(0,rr-ll+1);
}

int main(){
	int n;read(n);int ans=0;
	int pos1=0;int pos2=0;int mx_l=0;int n1=0;int n2=0;int mi_r=INT_MAX;
	rep(i,1,n){
		read(co[i].l);read(co[i].r);
		if(co[i].l>mx_l){mx_l=co[i].l;pos1=i;}
		if(co[i].r<mi_r){mi_r=co[i].r;pos2=i;}	
	}
	n1=co[pos1].r;n2=co[pos2].l;int len=0;
	rep(i,1,n){
		int q1=co[i].l;int q2=co[i].r;
		if(i!=pos1&&i!=pos2){co[++len].l=q1;co[len].r=q2;}
	}
	sort(co+1,co+len+1,cmp);
	
	int mx=co[1].r;int ret=d(co[1].l,co[1].r);
	rep(i,2,len){
		if(mx>=co[i].l)chkmax(ret,d(min(mx,co[i].r),co[i].l));
		chkmax(mx,co[i].r);chkmax(ret,d(co[i].l,co[i].r));
	}
	chkmax(ans,ret+d(mx_l,mi_r));
	
	if(pos1==pos2){write(ans);return 0;}
	int mi=n1;
	rep2(i,len,1){
		chkmax(ans,d(mx_l,mi)+d(co[i].l,mi_r));
		chkmin(mi,co[i].r);
	} 
	chkmax(ans,d(mx_l,mi)+d(n2,mi_r));write(ans);
	return 0;
}
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin>>n;
  ll l_max=0,r_min=1e10;
  vector<vector<ll>> v(n);
  ll res = 0;
  FOR(i,0,n){
    ll in,in1;
    cin>>in>>in1;
    in1++;
    v[i].push_back(0);
    v[i].push_back(in);
    v[i].push_back(in1);
    l_max = max(l_max,in);
    r_min = min(r_min,in1);
    res = max(res, in1-in);//max_width
  }
  res = res + max(r_min - l_max, (ll) 0);

  FOR(i,0,n) v[i][0] = max((ll)0, v[i][2]-l_max);
  sortAl(v);
  ll r=1e10,l=0;
  vector<ll> a(n),b(n);
  FOR(i,0,n){
    r = min(r,v[i][2]);
    l = max(l,v[i][1]);
    a[i] = max(r-l,(ll)0);
  }
  r = 1e10;
  l = 0;
  FORr(i,0,n-1){
    r = min(r,v[i][2]);
    l = max(l,v[i][1]);
    b[i] = max(r-l,(ll)0);
  }

  ll ans=0;
  FOR(i,0,n-1) ans = max(ans, a[i] + b[i+1]);
  cout<<max(ans,res)<<endl;
  


}