#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  multiset<int> L, R;
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(a, b);
    L.emplace(a);
    R.emplace(b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    L.erase(L.find(v[i].first));
    R.erase(R.find(v[i].second));
    auto lmax = L.end();
    lmax--;
    auto rmin = R.begin();
    ans = max(ans, *rmin - *lmax);
    L.emplace(v[i].first);
    R.emplace(v[i].second);
  }
  cout << ans << endl;
  return 0;
}
