#include <bits/stdc++.h>
using namespace std;
long long modulo = 1e9 + 7;
template <class X>
void printarr(X arr[], long long n) {
  for (long long i = 0; i < n; ++i) cout << arr[i] << " ";
  cout << "\n";
}
long long fpow(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = (ans * a) % modulo;
    a = (a * a) % modulo;
    n = n >> 1;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  pair<long long, long long> intervals[n];
  for (long long i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    intervals[i] = {a, b};
  }
  pair<long long, long long> pref[n + 1], suff[n + 1];
  pref[0] = {-LLONG_MAX, LLONG_MAX};
  suff[n] = {-LLONG_MAX, LLONG_MAX};
  for (long long i = 0; i < n; ++i) {
    pair<long long, long long> a = intervals[i], b = pref[i];
    if (a.first >= b.second or b.first >= a.second)
      pref[i + 1] = {0, 0};
    else
      pref[i + 1] = {max(a.first, b.first), min(a.second, b.second)};
  }
  for (long long i = n - 1; i > -1; --i) {
    pair<long long, long long> a = intervals[i], b = suff[i + 1];
    if (a.first >= b.second or b.first >= a.second)
      suff[i] = {0, 0};
    else
      suff[i] = {max(a.first, b.first), min(a.second, b.second)};
  }
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    pair<long long, long long> a = pref[i], b = suff[i + 1];
    if (a.first >= b.second or b.first >= a.second) continue;
    long long x = max(a.first, b.first), y = min(a.second, b.second);
    ans = max(ans, y - x);
  }
  cout << ans;
  return 0;
}
