#include <bits/stdc++.h>
using namespace std;
struct node {
  int num;
  int id;
};
bool cmp1(node x, node y) { return x.num < y.num; }
bool cmp2(node x, node y) { return x.num > y.num; }
node st[300005];
node ed[300005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int xx, yy;
    scanf("%d%d", &xx, &yy);
    node tmp;
    tmp.id = i;
    tmp.num = xx;
    st[i] = tmp;
    tmp.num = yy;
    ed[i] = tmp;
  }
  sort(st, st + n, cmp2);
  sort(ed, ed + n, cmp1);
  if (st[0].id == ed[0].id) {
    printf("%d\n", max(0, ed[1].num - st[1].num));
  } else {
    printf("%d\n", max(0, max(ed[0].num - st[1].num, ed[1].num - st[0].num)));
  }
  return 0;
}
