#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  int n;
  cin >> n;
  int a[n], b[n];
  map<pair<int, int>, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    m[{a[i], b[i]}] = 1;
  }
  sort(a, a + n);
  sort(b, b + n);
  int ans = -1;
  if (m[{a[n - 1], b[0]}] == 1) {
    ans = max(ans, b[1] - a[n - 2]);
  }
  ans = max(ans, b[1] - a[n - 1]);
  ans = max(ans, b[0] - a[n - 2]);
  if (ans < 0)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}
