#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int N = 3e5 + 5;
int n, a[N], b[N], x, y, i, j;
int main() {
  scanf("%d", &n);
  x = 0;
  y = INF;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    x = max(x, a[i]);
    y = min(y, b[i]);
  }
  int ans = y - x, tmp = 0, cnt = 0, id = 0;
  for (i = 0; i < n; i++)
    if (a[i] == x) cnt++, id = i;
  if (cnt == 1) {
    x = 0;
    y = INF;
    for (i = 0; i < n; i++) {
      if (i == id) continue;
      x = max(x, a[i]);
      y = min(y, b[i]);
    }
  }
  ans = max(ans, y - x);
  cnt = id = 0;
  for (i = 0; i < n; i++)
    if (b[i] == y) cnt++, id = i;
  if (cnt == 1) {
    x = 0;
    y = INF;
    for (i = 0; i < n; i++) {
      if (i == id) continue;
      x = max(x, a[i]);
      y = min(y, b[i]);
    }
  }
  ans = max(ans, y - x);
  if (ans <= 0)
    printf("0\n");
  else
    printf("%d\n", ans);
}
