#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  pair<long long, long long> arr[n], left[n + 1], right[n + 1];
  left[0] = {0, LLONG_MAX}, right[n] = {0, LLONG_MAX};
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    arr[i] = {a, b};
  }
  for (int i = 0; i < n; i++) {
    left[i + 1].first = max(left[i].first, arr[i].first);
    left[i + 1].second = min(left[i].second, arr[i].second);
  }
  for (int i = n - 1; i >= 0; i--) {
    right[i].first = max(right[i + 1].first, arr[i].first);
    right[i].second = min(right[i + 1].second, arr[i].second);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, min(left[i].second, right[i + 1].second) -
                       max(left[i].first, right[i + 1].first));
  }
  cout << ans << endl;
  return 0;
}
