#include <bits/stdc++.h>
using namespace std;
int l1[300005], l2[309000], r1[300006], r2[300005], ansl[300005], ansr[300005];
struct Node {
  int l, r;
} node[300005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &node[i].l, &node[i].r);
  }
  l1[1] = l2[n] = 0;
  r1[1] = r2[n] = 1e9;
  int Max = 0;
  for (int i = 2; i <= n; i++) {
    l1[i] = max(l1[i - 1], node[i - 1].l);
    r1[i] = min(r1[i - 1], node[i - 1].r);
  }
  for (int i = n - 1; i >= 1; i--) {
    l2[i] = max(l2[i + 1], node[i + 1].l);
    r2[i] = min(r2[i + 1], node[i + 1].r);
  }
  for (int i = 1; i <= n; i++) {
    ansl[i] = max(l1[i], l2[i]);
    ansr[i] = min(r1[i], r2[i]);
    Max = max(Max, ansr[i] - ansl[i]);
  }
  printf("%d\n", Max);
}
