#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> l(n),r(n),a(n),b(n),A(n),B(n);
  vector<pair<int,int>> c(n),d(n);
  int la=0,ra=1e9+5;
  int x=0,t;
  for(int i=0;i<n;i++){
    cin >> l[i] >> r[i];
    if(x<r[i]-l[i]+1){
      x=r[i]-l[i]+1;
      t=i;
    }
    c[i]=make_pair(l[i],r[i]);
    d[i]=make_pair(r[i],l[i]);
  }
  int L=0,R=1e9+5;
  for(int i=0;i<n;i++){
    if(i!=t){
      L=max(L,l[i]);
      R=min(R,r[i]);
    }
  }
  sort(c.begin(),c.end());
  sort(d.begin(),d.end());
  int lA=0,rA=1e9+5;
  for(int i=0;i<n;i++){
    la=max(la,c[i].first);
    ra=min(ra,c[i].second);
    a[i]=ra-la+1;
    lA=max(lA,d[i].second);
    rA=min(rA,d[i].first);
    A[i]=rA-lA+1;
  }
  int lb=0,rb=1e9+5;
  int lB=0,rB=1e9+5;
  for(int i=n-1;i>=0;i--){
    lb=max(lb,c[i].first);
    rb=min(rb,c[i].second);
    b[i]=rb-lb+1;
    lB=max(lB,d[i].second);
    rB=min(rB,d[i].first);
    B[i]=rB-lB+1;
  }
  int ans=0;
  for(int i=0;i<n-1;i++){
    ans=max(x+max(0,R-L+1),max(ans,max(a[i]+b[i+1],A[i]+B[i+1])));
  }
  cout << ans << endl;
}