#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int a[300001], b[300001], maks[300001], mini[300001], maks2[300001],
    mini2[300001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (i == 0) {
      maks[i] = a[i];
      mini[i] = b[i];
    } else {
      maks[i] = max(maks[i - 1], a[i]);
      mini[i] = min(mini[i - 1], b[i]);
    }
  }
  for (int i = n - 1; i > -1; i--) {
    if (i == n - 1) {
      maks2[i] = a[i];
      mini2[i] = b[i];
    } else {
      maks2[i] = max(maks2[i + 1], a[i]);
      mini2[i] = min(mini2[i + 1], b[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      ans = max(ans, mini2[i + 1] - maks2[i + 1]);
    } else if (i == n - 1) {
      ans = max(ans, mini[i - 1] - maks[i - 1]);
    } else {
      ans = max(
          ans, min(mini[i - 1], mini2[i + 1]) - max(maks[i - 1], maks2[i + 1]));
    }
  }
  cout << ans << "\n";
}
