#include <bits/stdc++.h>
using namespace std;
pair<int, int> q[300030];
int main() {
  multiset<int> a, b;
  int re = 0;
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> q[i].first >> q[i].second;
    a.insert(q[i].first);
    b.insert(q[i].second);
  }
  for (i = 0; i < n; i++) {
    a.erase(a.find(q[i].first));
    b.erase(b.find(q[i].second));
    re = max(re, *b.begin() - *a.rbegin());
    a.insert(q[i].first);
    b.insert(q[i].second);
  }
  cout << re << endl;
  return 0;
}
