#include <bits/stdc++.h>
using namespace std;
int l[300005], r[300005];
int max1 = -1, max2 = -1, min1 = 2e9 + 10000, min2 = 2e9 + 10000;
int i1, i2;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d%d", l + i, r + i);
  for (int i = 1; i <= n; i++) {
    if (l[i] > max1) {
      max1 = l[i];
      i1 = i;
    }
    if (r[i] < min1) {
      min1 = r[i];
      i2 = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (l[i] > max2 && i != i1) max2 = l[i];
    if (r[i] < min2 && i != i2) min2 = r[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int m1 = max1, m2 = min1;
    if (l[i] == m1) m1 = max2;
    if (r[i] == m2) m2 = min2;
    ans = max(ans, m2 - m1);
  }
  cout << ans;
  return 0;
}
