#include <bits/stdc++.h>
using namespace std;
const long long N = 200010;
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second > b.second;
  else
    return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > info, f, s;
  long long i;
  for (i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    info.push_back({x, y});
    f.push_back({x, y});
    s.push_back({y, x});
  }
  if (n == 2) {
    cout << max(info[0].second - info[0].first, info[1].second - info[1].first)
         << '\n';
    return 0;
  } else {
    pair<long long, long long> prefix[n + 5];
    pair<long long, long long> suffix[n + 5];
    long long minim = 1e18;
    long long maxim = 0;
    for (i = 0; i < n - 1; i++) {
      minim = min(minim, f[i].second);
      maxim = max(maxim, f[i].first);
      prefix[i].first = maxim;
      prefix[i].second = minim;
    }
    minim = 1e18;
    maxim = 0;
    for (i = n - 1; i > 0; i--) {
      maxim = max(maxim, s[i].second);
      minim = min(minim, s[i].first);
      suffix[i].first = maxim;
      suffix[i].second = minim;
    }
    long long ans = 0;
    for (i = 0; i < n; i++) {
      if (i == 0) {
        ans = max(ans, suffix[1].second - suffix[1].first);
      } else if (i == n - 1) {
        ans = max(ans, prefix[n - 2].second - prefix[n - 2].first);
      } else {
        ans = max(ans, min(prefix[i - 1].second, suffix[i + 1].second) -
                           max(prefix[i - 1].first, suffix[i + 1].first));
      }
    }
    cout << max(ans, (long long)0) << '\n';
  }
  return 0;
}
