#include <bits/stdc++.h>
using namespace std;
int call(int idx, vector<pair<int, int> >& vec) {
  int r = INT_MAX;
  int l = INT_MIN;
  for (int i = 0; i < vec.size(); i++) {
    if (idx == i) continue;
    r = min(r, vec[i].first);
    l = max(l, vec[i].second);
  }
  return r - l;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > vec(n, make_pair(0, 0));
  for (int i = 0; i < n; i++) scanf("%d %d", &vec[i].second, &vec[i].first);
  sort(vec.begin(), vec.end());
  int ridx, r = INT_MAX;
  int lidx, l = INT_MIN;
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i].first < r) {
      r = vec[i].first;
      ridx = i;
    }
    if (l < vec[i].second) {
      l = vec[i].second;
      lidx = i;
    }
  }
  int ans = 0;
  ans = max(ans, call(lidx, vec));
  ans = max(ans, call(ridx, vec));
  printf("%d\n", ans);
  return 0;
}
