#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v(n);
  for (auto &i : v) cin >> i.first >> i.second;
  sort(v.begin(), v.end());
  vector<pair<long long, long long>> suf(n);
  suf[n - 1] = v[n - 1];
  for (long long i = n - 2; i >= 0; i--) {
    suf[i].first = max(v[i].first, suf[i + 1].first);
    suf[i].second = min(v[i].second, suf[i + 1].second);
  }
  long long ans = 0;
  pair<long long, long long> pref = {-1, INT_MAX};
  for (long long i = 0; i < n - 1; i++) {
    ans = max(ans, min(suf[i + 1].second, pref.second) -
                       max(suf[i + 1].first, pref.first));
    pref.first = max(pref.first, v[i].first);
    pref.second = min(pref.second, v[i].second);
  }
  ans = max(ans, pref.second - pref.first);
  cout << ans;
  return 0;
}
