#include <bits/stdc++.h>
using namespace std;
long long n, l[300000], r[300000], ans, dl = 1e15;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    dl = min(dl, r[i] - l[i]);
  }
  sort(l, l + n);
  sort(r, r + n);
  if (r[0] - l[n - 1] == dl) ans = r[1] - l[n - 2];
  ans = max(ans, r[0] - l[n - 2]);
  ans = max(ans, r[1] - l[n - 1]);
  cout << ans;
  return 0;
}
