#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, k, t;
pair<int, int> a[300100], b[300100];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> b[i].first;
    a[i].second = b[i].second = i + 1;
  }
  sort(a, a + n);
  sort(b, b + n);
  for (int i = 1; i <= n; i++) {
    x = a[n - 1].first;
    if (i == a[n - 1].second) x = a[n - 2].first;
    y = b[0].first;
    if (i == b[0].second) y = b[1].first;
    z = max(m, y - x);
    k = max(k, z);
  }
  cout << k;
  return 0;
}
