#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> l(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  vector<int> prh(n), prl(n), srh(n), srl(n);
  prh[0] = r[0];
  prl[0] = l[0];
  for (int i = 1; i < n; i++) {
    prh[i] = min(prh[i - 1], r[i]);
    prl[i] = max(prl[i - 1], l[i]);
  }
  srh[n - 1] = r[n - 1], srl[n - 1] = l[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    srh[i] = min(srh[i + 1], r[i]);
    srl[i] = max(srl[i + 1], l[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      ans = max(ans, srh[1] - srl[1]);
    } else if (i == n - 1) {
      ans = max(ans, prh[n - 2] - prl[n - 2]);
    } else {
      ans = max(ans, min(prh[i - 1], srh[i + 1]) - max(prl[i - 1], srl[i + 1]));
    }
  }
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
