#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > v(n);
  multiset<int> l, r;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &v[i].first, &v[i].second);
    l.insert(v[i].first);
    r.insert(v[i].second);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    l.erase(l.find(v[i].first));
    r.erase(r.find(v[i].second));
    ans = max(ans, *r.begin() - *--l.end());
    l.insert(v[i].first);
    r.insert(v[i].second);
  }
  printf("%d\n", ans);
  return 0;
}
