#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int>> arr(n);
  multiset<int> l, r;
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
    l.insert(arr[i].first);
    r.insert(arr[i].second);
  }
  int ans = 0;
  for (const auto &[lb, rb] : arr) {
    r.erase(r.lower_bound(rb));
    l.erase(l.lower_bound(lb));
    ans = max(ans, *r.begin() - *l.rbegin());
    l.insert(lb);
    r.insert(rb);
  }
  cout << ans << '\n';
}
