#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define rep(i,N) For(i,0,N)
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

int main(){
  ll i,N,ans=0,mar=0,mil=1LL<<60;
  cin>>N;
  vector<pair<ll,ll>> v(N);
  multiset<ll> se;
  rep(i,N){
    cin>>v[i].first>>v[i].second;
    v[i].first--;
    chmax(mar,v[i].first);
    chmin(mil,v[i].second);
    chmax(ans,v[i].second-v[i].first);
    se.insert(v[i].second);
    v[i].second*=-1;
  }
  ans+=max(mil-mar,0LL);
  sort(v.begin(),v.end());
  se.erase(se.find(-v[0].second));
  mil=-v[0].second;
  for(i=1;i<N;i++){
    chmax(ans,max(0LL,*se.begin()-v[N-1].first)+max(0LL,mil-v[i-1].first));
    se.erase(se.find(-v[i].second));
    chmin(mil,-v[i].second);
  }
  cout<<ans<<endl;
  return 0;
}