#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(T& x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x = f ? -x : x;
}
const int N = 3e5 + 10;
int n, i, x[N], y[N];
vector<int> vx, vy;
int main() {
  read(n);
  for (i = 1; i <= n; i++) {
    read(x[i]), read(y[i]);
    vx.emplace_back(x[i]);
    vy.emplace_back(y[i]);
  }
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());
  int ans = max(vy[0] - vx[(int)vx.size() - 1], 0);
  for (i = 1; i <= n; i++) {
    int l = vx[(int)vx.size() - 1], r = vy[0];
    if (l == x[i]) {
      l = vx[(int)vx.size() - 2];
    }
    if (r == y[i]) {
      r = vy[1];
    }
    ans = max(ans, max(r - l, 0));
  }
  printf("%d\n", ans);
  return 0;
}
