#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

int N=1<<18;
class StarrySkyTree{
public:
  ll Ma[555555],A[555555];
  void init(){memset(Ma,0,sizeof(Ma)),memset(A,0,sizeof(A));}
  void add(int a,int b,ll x,int k=0,int l=0,int r=N) {
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      A[k]+=x;
      while(k){
        k=(k-1)/2;
        Ma[k]=max(Ma[k*2+1]+A[k*2+1],Ma[k*2+2]+A[k*2+2]);
      }
      return;
    }
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }
  ll getMax(int a,int b,int k=0,int l=0,int r=N) {
    if(r<=a||b<=l)return -LLONG_MAX;if(a<=l&&r<=b)return Ma[k]+A[k];
    ll left=getMax(a,b,k*2+1,l,(l+r)/2),right=getMax(a,b,k*2+2,(l+r)/2,r);
    return max(left,right)+A[k];
  }
};

StarrySkyTree t[2];
ll n;
vector<ll> v;

ll solve(ll k,ll i) {
  ll l=-1,r=v.size()-1;
  while(l+1<r) {
    ll m=(l+r)/2;
    if(t[i].getMax(0,m+1)<k) l=m;
    else r=m;
  }
  ll e=r;
  l=0,r=v.size();
  while(l+1<r) {
    ll m=(l+r)/2;
    if(t[i].getMax(m,v.size())<k) r=m;
    else l=m;
  }
  return max(0LL,v[l]-v[e]+1);
}

map<ll,ll> ma;

void IN(ll x) {
  ll k=ma.size();
  ma[x]=k;
}

void Main() {
  rep(i,2) t[i].init();
  R n;
  P a[n];
  rep(i,n) cin >> a[i].S >> a[i].F;
  sort(a,a+n);
  rep(i,n) swap(a[i].F,a[i].S);
  set<ll> s;
  rep(i,n) {
    s.in(a[i].F);
    s.in(a[i].S);
  }
  tr(it,s) {
    IN(*it);
    v.pb(*it);
  }
  rep(i,n) {
    a[i].F=ma[a[i].F];
    a[i].S=ma[a[i].S];
  }
  rep(i,n) t[1].add(a[i].F,a[i].S+1,1);
  ll ans=0,l1=0,r1=0,l2=0,r2=0;
  rep(i,n-1) {
    t[0].add(a[i].F,a[i].S+1,1);
    t[1].add(a[i].F,a[i].S+1,-1);
    while(l1<=a[i].S&&t[0].getMax(0,l1)<i+1) l1++;
    while(r1<=a[i].S&&t[0].getMax(r1,v.size())>=i+1) r1++;
    while(l2<v.size()&&t[1].getMax(0,l2)<n-i-1) l2++;
    while(r2<v.size()&&t[1].getMax(r2,v.size())>=n-i-1) r2++;
    ll x1=v[l1-1],y1=v[r1-1],x2=v[l2-1],y2=v[r2-1];
    //cout << i << " " << max(0LL,y1-x1+1) << " " << max(0LL,y2-x2+1) << " " << solve(i+1,0) << " " << solve(n-i-1,1) << endl;
    ans=max(ans,max(0LL,y1-x1+1)+max(0LL,y2-x2+1));
    //ans=max(ans,solve(i+1,0)+solve(n-i-1,1));
  }
  rep(i,2) t[i].init();
  rep(i,n) t[1].add(a[i].F,a[i].S+1,1);
  rep(i,n) {
    if(i) {
      t[0].add(a[i-1].F,a[i-1].S+1,-1);
      t[1].add(a[i-1].F,a[i-1].S+1,1);
    }
    t[0].add(a[i].F,a[i].S+1,1);
    t[1].add(a[i].F,a[i].S+1,-1);
    ans=max(ans,v[a[i].S]-v[a[i].F]+1+solve(n-1,1));
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 44656