#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define INF (100000000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;

  map<long, long> contests;

  vector<pair<long, long>> LR;
  vector<long> L;
  vector<long> R;

  long max_prob = 0;
  rep (i, N) {
    long l, r;
    cin >> l >> r;
    LR.push_back(make_pair(l, r));
    L.push_back(l);
    R.push_back(r);
    max_prob = max(max_prob, r - l + 1);
    if (contests.count(l) == 0) contests[l] = r;
    else contests[l] = min(contests[l], r);
  }
  if (contests.size() == 1) {
    auto it = contests.end();
    it--;
    long last_L = it->first;
    long last_R = it->second;
    cout << last_R - last_L + 1 + max_prob << endl;
    return;
  }

  long one_and_else_ans = 0;

  {
    // 1問とその他に分けるケースのカバー
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    sort(R.begin(), R.end());
    for (auto it: LR) {
      long f_L = it.first;
      long f_R = it.second;
      long f_score = f_R - f_L + 1;
      long s_L = L[0];
      long s_R = R[0];
      if (s_L == f_L) s_L = L[1];
      if (s_R == f_R) s_R = R[1];
      long s_score = s_R - s_L + 1;
      one_and_else_ans = max(one_and_else_ans, f_score + s_score);
    }
  }

/*
  {
    map<long, long> tmp = contests;
    auto it = contests.end();
    it--;
    long last_L = it->first;
    long last_R = it->second;
    for (auto it: tmp) {
      if (it.first == last_L) continue;
      if (it.second >= last_R) contests.erase(it.first);
    }
    if (contests.size() == 1) {
      cout << last_R - last_L + 1 + max_prob << endl;
      return;
    }
  }
*/

  vector<pair<long, long>> RL;
  for (auto it: contests) {
    RL.push_back(make_pair(it.second, it.first));
  }
  RL.pop_back();
  sort(RL.begin(), RL.end());

  map<long, pair<long, long>> memo;
  auto current_pair = RL[0];
  memo[current_pair.first] = current_pair;
  for (long i = 1; i < RL.size(); i++) {
    auto xxx = RL[i];
    pair<long, long> next_pair = make_pair(min(current_pair.first, xxx.first), max(current_pair.second, xxx.second));
    current_pair = next_pair;
    memo[xxx.first] = current_pair;
  }

  auto it = contests.end();
  it--;
  long last_L = it->first;
  long last_R = it->second;

/*
  cout << "last_L=" << last_L << ", last_R=" << last_R << endl;
  for (auto it: memo) {
    cout << it.first << " : " << it.second.first << " , " << it.second.second << endl;;
  }
  return;
*/


  long ans_split = max_prob; // 2問目が0点のときをカバーする

  for (auto it: memo) {
    long current_R = it.second.first;
    long current_L = it.second.second;
    long first_score = current_R - current_L + 1;
    if (first_score < 0) first_score = 0;
    pair<long, long> ppp = make_pair(it.first, INF);
    auto ppp_it = upper_bound(RL.begin(), RL.end(), ppp);
    long second_R = last_R;
    if (ppp_it == RL.end()) second_R = last_R;
    else second_R = min(last_R, ppp_it->first);
    long second_score = second_R - last_L + 1;
    if (second_score < 0) second_score = 0;
    ans_split = max(ans_split, first_score + second_score);
  }

  long ans = max(ans_split, one_and_else_ans);

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 18416