#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i] >> b[i];
  long long pre_a[n], pre_b[n], su_a[n], su_b[n];
  long long l = -1, r = 1e15;
  for (long long i = 0; i < n - 1; i++) {
    if (l < a[i]) l = a[i];
    if (r > b[i]) r = b[i];
    pre_a[i + 1] = l;
    pre_b[i + 1] = r;
  }
  l = -1;
  r = 1e15;
  for (long long i = n - 1; i > 0; i--) {
    if (l < a[i]) l = a[i];
    if (r > b[i]) r = b[i];
    su_a[i - 1] = l;
    su_b[i - 1] = r;
  }
  long long ans = 0;
  for (long long i = 1; i < n - 1; i++) {
    if (su_b[i] - su_a[i] < 0 || pre_b[i] - pre_a[i] < 0) {
      continue;
    }
    long long x = max(pre_a[i], su_a[i]);
    long long y = min(pre_b[i], su_b[i]);
    ans = max(ans, y - x);
  }
  ans = max(ans, pre_b[n - 1] - pre_a[n - 1]);
  ans = max(ans, su_b[0] - su_a[0]);
  cout << ans;
  return 0;
}
