#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) 42
//#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

bool my_compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first > b.first; // firstの大きい順
    }else{
        return a.second < b.second; // secondの小さい順
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N; 
    cin >> N;

    VI L(N);
    VI R(N);
    rep(i, N){
        cin >> L.at(i) >> R.at(i);
    }

    auto sorted_L = L; SORT(sorted_L);
    auto sorted_R = R; SORT(sorted_R);

    ll max_left = sorted_L.back();
    ll min_right = sorted_R[0];

    ll ma = 0;
    // １つのみ分離
    rep(i, N){
      ll r = min_right;
      ll l = max_left;
      // iのみ除外
      if(L[i]==max_left){
        l = sorted_L[N-2];
      }
      if(R[i]==min_right){
        r = sorted_R[1];
      }
      ll range = max(r-l+1, 0LL);
      ll score = range + (R[i]-L[i]+1);
      chmax(ma, score);
    }

    // L max index
    ll p = distance(L.begin(), max_element(ALL(L)));
    // R min index
    ll q = distance(R.begin(), min_element(ALL(R)));
    rep(i, N){
      if(i==p || i==q) continue;
      ll range = min_right - max_left + 1;
      ll score = range + (R[i]-L[i]+1);
      chmax(ma, score);
    }

    // p, qを違う集合に含める場合
    VI A(N);
    VI B(N);
    vector<pair<ll, ll>> P;
    rep(i, N){
      if(i==p || i==q) continue;
      A[i] = max(R[i] - max_left + 1, 0LL);
      B[i] = max(min_right - L[i] + 1, 0LL);
      P.push_back(make_pair(A[i], B[i]));
    }
    // firstの大きい順、secondの小さい順にソート
    // 先頭のi個を右側のコンテストに割り当てる
    sort(ALL(P), my_compare);
    debug(P);

    ll left = inf;
    multiset<ll> se;

    for(auto p : P){
      se.insert(p.second);
    }
    debug(se.size());
    rep(i, P.size()){
      // first側
      chmin(left, P[i].first);
      debug(left);

      // second側
      auto it = se.find(P[i].second); // これを消す
      se.erase(it);
      debug(se.size());
      ll right = 0;
      if(se.size()>0){
        right = *(se.begin()); // 最小値
        debug("a", right);
      }
      ll score = left+right;
      chmax(ma, score);
    }



    p(ma);
    
    return 0;
}

Measured memory_bytes: 11248