#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int a[maxn];
int b[maxn];
struct poi {
  int x, y;
} mapp[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    mapp[i].x = a[i];
    mapp[i].y = b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  int res = -1;
  for (int i = 1; i <= n; i++) {
    int ll = mapp[i].x;
    int rr = mapp[i].y;
    bool flag_l = true;
    bool flag_r = true;
    for (int k = n; k > 0; k--) {
      if (flag_l) {
        if (a[k] > ll) {
          flag_l = false;
          ll = a[k];
          break;
        } else if (a[k] == ll) {
          flag_l = false;
          continue;
        }
      } else {
        ll = a[k];
        break;
      }
    }
    for (int k = 1; k <= n; k++) {
      if (flag_r) {
        if (b[k] < rr) {
          rr = b[k];
          break;
        } else if (b[k] == rr) {
          flag_r = false;
          continue;
        }
      } else {
        rr = b[k];
        break;
      }
    }
    res = max(res, rr - ll);
  }
  if (res >= 0)
    cout << res;
  else
    cout << "0";
}
