#include <bits/stdc++.h>
using namespace std;
long long inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 1000000000000000000;
multiset<int> l, r;
int L[300005] = {};
int R[300005] = {};
int main() {
  int a;
  while (cin >> a) {
    for (int i = 0; i < a; i++) {
      cin >> L[i] >> R[i];
      l.insert(L[i]);
      r.insert(R[i]);
    }
    int ans = 0;
    for (int i = 0; i < a; i++) {
      l.erase(l.find(L[i]));
      r.erase(r.find(R[i]));
      ans = max(ans, *r.begin() - *l.rbegin());
      l.insert(L[i]);
      r.insert(R[i]);
    }
    cout << ans << '\n';
  }
  return 0;
}
