#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
int t, mit;
struct node {
  int l, r;
};
bool cmp(node a, node b) { return a.l < b.l; }
node num[maxn];
int main() {
  int flag = 0, temi = 0;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) scanf("%d%d", &num[i].l, &num[i].r);
  sort(num + 1, num + 1 + t, cmp);
  int rmit = 1 << 30;
  for (int i = 1; i <= t; i++) {
    if (num[i].l >= rmit) {
      temi = num[i].l;
      flag = 1;
      break;
    } else {
      rmit = min(rmit, num[i].r);
    }
  }
  int minn = 1 << 30, maxx = -1, max2 = -1, ans1, ans2;
  int fg;
  if (flag == 0) {
    for (int i = 1; i <= t; i++) minn = min(minn, num[i].r);
    for (int i = 1; i <= t; i++) max2 = max(maxx, num[i].l);
  } else {
    minn = rmit;
    max2 = temi;
  }
  for (int i = 1; i <= t; i++) {
    if (num[i].r == minn) {
      if (maxx < num[i].l) {
        maxx = num[i].l;
        fg = i;
      }
    }
  }
  minn = 1 << 30, maxx = -1;
  for (int i = 1; i <= t; i++) {
    if (i != fg) {
      maxx = max(maxx, num[i].l);
      minn = min(minn, num[i].r);
    }
  }
  ans1 = minn - maxx;
  minn = 1 << 30, maxx = -1;
  for (int i = 1; i <= t; i++) {
    if (num[i].l == max2) {
      if (minn > num[i].r) {
        minn = num[i].r;
        fg = i;
      }
    }
  }
  minn = 1 << 30, maxx = -1;
  for (int i = 1; i <= t; i++) {
    if (i != fg) {
      maxx = max(maxx, num[i].l);
      minn = min(minn, num[i].r);
    }
  }
  ans2 = minn - maxx;
  int ans3 = max(ans1, ans2);
  if (ans3 <= 0)
    printf("0\n");
  else
    printf("%d\n", ans3);
}
