#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define endl "\n"
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define N_MAX (1<<17)
#define INF 1000000000000000000LL

struct segmn{
  long long nn;
  long long dat[(2 * N_MAX) - 1];

  void init(long long n1){
    nn = 1;

    while(nn < n1)nn *= 2;

    for(long long i = 0; i < 2 * nn - 1; i++){
      dat[i] = INF;
    }
  }

  void update(long long k, long long a){
    k += nn - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  long long query(long long a, long long b, long long k, long long l, long long r){
    if(r <= a || b <= l)return INF;

    if(a <= l && r <= b){
      return dat[k];
    }
    else{
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }

  long long query(long long a, long long b){
    return query(a,b,0,0,nn);
  }
}segmn1,segmn2;

struct segmx{
  long long nn;
  long long dat[(2 * N_MAX) - 1];

  void init(long long n1){
    nn = 1;

    while(nn < n1)nn *= 2;

    for(long long i = 0; i < 2 * nn - 1; i++){
      dat[i] = -INF;
    }
  }

  void update(long long k, long long a){
    k += nn - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  long long query(long long a, long long b, long long k, long long l, long long r){
    if(r <= a || b <= l)return -INF;

    if(a <= l && r <= b){
      return dat[k];
    }
    else{
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return max(vl, vr);
    }
  }

  long long query(long long a, long long b){
    return query(a,b,0,0,nn);
  }
}segmx2;

int main(){
  ll n;
  cin>>n;
  vector<pair<pair<ll,ll>,ll> > v1;
  vector<pair<pair<ll,ll>,ll> > v2;
  rep(i,0,n){
    ll a,b;
    cin>>a>>b;
    v1.pb(mp(mp(b,a),i));
    v2.pb(mp(mp(a,b),i));
  }
  if(n==2){
    cout << v2[0].fi.se-v2[0].fi.fi+1+v2[1].fi.se-v2[1].fi.fi+1 << endl;
    return 0;
  }
  sort(all(v1));
  sort(all(v2));reverse(all(v2));
  ll mx = 0;
  if(v1[0].se!=v2[0].se){
    ll index1 = v1[0].se;
    ll index2 = v2[0].se;
    vector<pair<ll,ll> > v;
    rep(i,0,n){
      ll l = v1[i].fi.se;
      ll r = v1[i].fi.fi;
      ll index = v1[i].se;
      if(index==index1)continue;
      if(index==index2)continue;
      v.pb(mp(l,r));
    }
    sort(all(v));
    segmn1.init(v.sz);
    rep(i,0,v.sz){
      segmn1.update(i,v[i].se);
    }
    ll l1 = v1[0].fi.se;
    ll r1 = v1[0].fi.fi;
    ll l2 = v2[0].fi.fi;
    ll r2 = v2[0].fi.se;
    ll a1 = max(0LL,r1-l1+1);
    ll b1 = max(0LL,min(r2,segmn1.query(0,v.sz))-l2+1);
    mx = max(mx,a1+b1);
    ll a2 = max(0LL,r1-max(l1,v[v.sz-1].fi)+1);
    ll b2 = max(0LL,r2-l2+1);
    mx = max(mx,a2+b2);    
    rep(i,0,v.sz-1){
      ll a3 = max(0LL,r1-max(l1,v[i].fi)+1);
      ll b3 = max(0LL,min(r2,segmn1.query(i+1,v.sz))-l2+1);
      mx = max(mx,a3+b3);
    }
  }
  else{
    ll index1 = v1[0].se;
    ll l1 = v1[0].fi.se;
    ll r1 = v1[0].fi.fi;
    ll mx1 = 0;
    rep(i,0,n){
      ll l = v1[i].fi.se;
      ll r = v1[i].fi.fi;
      ll index = v1[i].se;
      if(index==index1)continue;
      mx1 = max(mx1,r-l+1);
    }
    mx = r1-l1+1+mx1;
  }
  segmn2.init(v2.sz);
  segmx2.init(v2.sz);
  rep(i,0,v2.sz){
    segmx2.update(i,v2[i].fi.fi);
    segmn2.update(i,v2[i].fi.se);
  }
  rep(i,0,v2.sz){
    ll l1 = v2[i].fi.fi;
    ll r1 = v2[i].fi.se;
    ll l2 = max(segmx2.query(0,i),segmx2.query(i+1,v2.sz));
    ll r2 = min(segmn2.query(0,i),segmn2.query(i+1,v2.sz));
    ll a1 = max(0LL,r1-l1+1);
    ll b1 = max(0LL,r2-l2+1);
    mx = max(mx,a1+b1);
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 13832