#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  multiset<pair<int, int>> lr, rl, cp;
  for (int i = 0; i < n; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    lr.insert({l, r});
    rl.insert({r, l});
  }
  cp = lr;
  int res = 0;
  for (auto p : cp) {
    pair<int, int> pp = {p.second, p.first};
    lr.erase(lr.find(p));
    rl.erase(rl.find(pp));
    res = max(res, rl.begin()->first - lr.rbegin()->first);
    lr.insert(p);
    rl.insert(pp);
  }
  cout << res;
  return 0;
}
