#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v;
  long long x, y;
  long long i, j;
  for (i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  long long mini1, mini2;
  mini1 = INT_MAX;
  mini2 = INT_MAX;
  for (i = 0; i < n; i++) {
    long long a, b;
    a = v[i].first;
    b = v[i].second;
    if (mini1 > b) {
      mini2 = mini1;
      mini1 = b;
    } else if (mini2 > b) {
      mini2 = b;
    }
  }
  long long c1 = 0, c2 = 0;
  for (i = 0; i < n; i++) {
    long long a, b;
    a = v[i].first;
    b = v[i].second;
    if (b == mini1) c1++;
    if (b == mini2) c2++;
  }
  if (c1 > 1) mini2 = mini1;
  long long ans = 0;
  for (i = 0; i < n; i++) {
    long long a, b;
    a = v[i].first;
    b = v[i].second;
    long long l, r;
    l = v[n - 1].first;
    if (i == n - 1) {
      l = v[n - 2].first;
    }
    if (b == mini1) {
      r = mini2;
    } else
      r = mini1;
    ans = max(ans, r - l);
  }
  cout << ans;
  return 0;
}
