/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
    
  lint n; cin >> n;
  vector<lint> l(n);
  vector<lint> r(n);
  for(int i = 0; i < n; i++) cin >> l[i] >> r[i];

  if(n == 2) {
    cout << r[0] - l[0] + r[1] - l[1] + 2 << endl;
    return 0;
  }

  lint mi;
  lint mr = INF;
  lint Mi;
  lint Ml = -1;
  lint lb, rb, la, ra;
  for(int i = 0; i < n; i++) {
    if(mr > r[i]) {
      mr = r[i];
      mi = i;
    }
    if(Ml < l[i]) {
      Ml = l[i];
      Mi = i;
    }
  }

  for(int i = 0; i < n; i++) {
    if(i == mi) {
      rb = r[i];
      lb = l[i];
    }
    if(i == Mi) {
      la = l[i];
      ra = r[i];
    }
  }

  vector<pair<lint, lint>> rest;
  for(int i = 0; i < n; i++) {
    if(i == mi or i == Mi) continue;
    rest.push_back({l[i], r[i]});
  }

  lint ans = 0;
  // mr, Ml を一緒にする場合
  ans = max(mr - Ml + 1, 0LL);
  lint add = 0;
  for(int i = 0; i < rest.size(); i++) {
    add = max(add, rest[i].second - rest[i].first + 1);
  }
  ans += add;

  
  // 一緒にしない場合
  sort(ALL(rest));
  vector<lint> min_r(n - 2, INF);
  min_r[n - 3] = rest[n - 3].second;
  for(int i = n - 4; i >= 0; i--) {
    min_r[i] = min(min_r[i + 1], rest[i].second);
  }
  // rest の内から i こを青に
  for(int i = 0; i <= n - 2; i++) {
    lint ll = lb;
    if(i != 0) {
      ll = rest[i - 1].first;
    }
    lint blue = max(rb - ll + 1, 0LL);
    lint rr = ra;
    if(i != n - 2) {
      rr = min_r[i];
    }
    lint red = max(rr - la + 1, 0LL);
    ans = max(ans, blue + red);
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4980