#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long double eps = 1e-10;
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;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<long long, long long>> P(n);
  vector<long long> p;
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> P[i].first >> P[i].second;
    P[i].first--;
    p.push_back(P[i].first);
    p.push_back(P[i].second);
  }
  sort(p.begin(), p.end());
  p.erase(unique(p.begin(), p.end()), end(p));
  vector<pair<int, int>> pi(n);
  vector<int> cnt(p.size());
  for (int i = (int)(0); i < (int)(n); i++) {
    pi[i].first = lower_bound(p.begin(), p.end(), P[i].first) - begin(p);
    pi[i].second = lower_bound(p.begin(), p.end(), P[i].second) - begin(p);
    cnt[pi[i].first]++;
    cnt[pi[i].second]--;
  }
  vector<long long> sum_n_1(p.size() + 1);
  long long sum_n = 0;
  int tmp = 0;
  for (int i = (int)(0); i < (int)(p.size()); i++) {
    tmp += cnt[i];
    sum_n_1[i + 1] += sum_n_1[i];
    if (tmp == n - 1) sum_n_1[i + 1] += p[i + 1] - p[i];
    if (tmp == n) sum_n += p[i + 1] - p[i];
  }
  long long ans = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    chmax(ans, sum_n + sum_n_1.back() -
                   (sum_n_1[pi[i].second] - sum_n_1[pi[i].first]));
  }
  cout << max(0LL, ans - 1) << '\n';
  return 0;
}
