#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, l, r, ans = 0, val;
  cin >> n;
  vector<pair<int, int>> st, te;
  vector<int> ar, res(2 * n + 1), pref(2 * n + 1);
  for (int i = (0); i < n; i++) {
    cin >> l >> r;
    st.push_back({l, r});
    ar.push_back(l), ar.push_back(r + 1);
  }
  sort(ar.begin(), ar.end());
  ar.resize(unique(ar.begin(), ar.end()) - ar.begin());
  for (auto it : st) {
    l = lower_bound(ar.begin(), ar.end(), it.first) - ar.begin();
    r = lower_bound(ar.begin(), ar.end(), it.second + 1) - ar.begin();
    pref[l]++, pref[r]--;
  }
  for (int i = (1); i < 2 * n + 1; i++) pref[i] += pref[i - 1];
  for (int i = (0); i < 2 * n + 1; i++) {
    if (pref[i] < n - 1) continue;
    int fl = 0;
    ans = max(ans, ar[i + 1] - ar[i] - 1);
    if (pref[i] == n) {
      if (pref[i] - pref[i + 1] == 1)
        ans = max(ans, ar[i + 2] - ar[i] - 1), fl++;
      if (pref[i] - pref[i - 1] == 1)
        ans = max(ans, ar[i + 1] - ar[i - 1] - 1), fl++;
      if (fl == 2) {
        te.push_back({ar[i], ar[i + 1] - 1});
        if (i + 2 < ar.size()) val = ar[i + 2] - ar[i - 1] - 1;
      }
    }
  }
  if (te.size()) {
    for (auto it : st) {
      if (it == te[0]) {
        ans = val;
        break;
      }
    }
  }
  cout << ans << endl;
}
