#include <bits/stdc++.h>
using namespace std;
multiset<int> a, b;
int c[300010], d[300010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i] >> d[i];
    a.insert(c[i]);
    b.insert(d[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    a.erase(a.find(c[i]));
    b.erase(b.find(d[i]));
    ans = max(ans, *b.begin() - *a.rbegin());
    a.insert(c[i]);
    b.insert(d[i]);
  }
  cout << ans << endl;
}
