#include <bits/stdc++.h>
using namespace std;
struct Segment {
  int l, r;
  struct Segment operator+(const struct Segment &R) {
    return (Segment){max(l, R.l), min(r, R.r)};
  };
  int toInt() {
    if (r <= l)
      return 0;
    else
      return r - l;
  }
} a[300000], tree[3 * 300000];
void update(int l, int r, int ptr, int t, Segment &v) {
  if (l == r && l == t) {
    tree[ptr] = v;
    return;
  }
  int m = (l + r) / 2;
  if (t <= m)
    update(l, m, 2 * ptr + 1, t, v);
  else
    update(m + 1, r, 2 * ptr + 2, t, v);
  tree[ptr] = tree[2 * ptr + 1] + tree[2 * ptr + 2];
}
int main() {
  int n;
  Segment null = (Segment){INT_MIN, INT_MAX};
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", &a[i].l, &a[i].r);
  for (int i = 0; i < n; i++) update(0, n - 1, 0, i, a[i]);
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    update(0, n - 1, 0, i, null);
    maxi = max(maxi, tree[0].toInt());
    update(0, n - 1, 0, i, a[i]);
  }
  printf("%d\n", maxi);
}
