#include <bits/stdc++.h>
using namespace std;
const int N = 333333, INF = 1e9 + 19;
int l[N], r[N];
int n;
int calci(int rem) {
  int mr = INF, ml = -INF;
  for (int i = (1); i <= (n); i++) {
    if (i == rem) continue;
    mr = min(mr, r[i]);
    ml = max(ml, l[i]);
  }
  return max(0, mr - ml);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int mri = -1, mli = -1;
  for (int i = (1); i <= (n); i++) {
    cin >> l[i] >> r[i];
    if (mri == -1 || r[mri] > r[i]) {
      mri = i;
    }
    if (mli == -1 || l[mli] < l[i]) {
      mli = i;
    }
  }
  int ans = max(calci(mri), calci(mli));
  cout << ans << "\n";
  return 0;
}
