#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
string str;
long long premin[300005], premax[300005], postmin[300005], postmax[300005];
long long solve() {
  cin >> n;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i <= n + 1; ++i) {
    premin[i] = 1000000000000000;
    postmin[i] = 1000000000000000;
    premax[i] = -1000000000000000;
    postmax[i] = -1000000000000000;
  }
  v.push_back({0, 0});
  for (long long i = 0; i <= n - 1; ++i) {
    long long a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  for (long long i = 1; i <= n; ++i) {
    premin[i] = min(premin[i - 1], v[i].second);
    premax[i] = max(premax[i - 1], v[i].first);
  }
  for (long long i = n; i >= 1; --i) {
    postmin[i] = min(postmin[i + 1], v[i].second);
    postmax[i] = max(postmax[i + 1], v[i].first);
  }
  ans = max(ans, postmin[2] - postmax[2]);
  ans = max(ans, premin[n - 1] - premax[n - 1]);
  for (long long i = 2; i <= n - 1; ++i) {
    ans = max(ans, min(postmin[i + 1], premin[i - 1]) -
                       max(postmax[i + 1], premax[i - 1]));
  }
  cout << ans;
  return 0;
}
signed main() {
  ios::sync_with_stdio(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
