#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)


ll len(pair<ll,ll> x){
  return max(0LL,x.second-x.first+1LL);
}

int main(){ 

  ll N,ans=0;
  cin >> N;
  vector< pair<ll,ll> > LR(N);
  FOR(i,0,N)cin>>LR[i].first>>LR[i].second;

  sort(LR.begin(), LR.end());

  vector< pair<ll,ll> > fun_big(N),fun_end(N);

  ll l = 0,r=1e9+7;
  FOR(i,0,N){
    ans = max(ans,LR[i].second-LR[i].first+1);
    l = max(l,LR[i].first);
    r = min(r,LR[i].second);
    fun_big[i] = {l,r};
  }

  l = 0,r=1e9+7;
  FORR(i,0,N){
    l = max(l,LR[i].first);
    r = min(r,LR[i].second);
    fun_end[i] = {l,r};
  }

  FOR(i,0,N-1){
    ans = max( ans , len(fun_big[i]) + len(fun_end[i+1]));
    if(i){
      ll l = max(fun_big[i-1].first,fun_end[i+1].first);
      ll r = min(fun_big[i-1].second,fun_end[i+1].second);
      ans = max( ans , len(LR[i]) + len({l,r}) );
    }
  }
  cout << ans << endl;

}
