#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int>> seg(n);
  for (int i = 0; i < n; i++) cin >> seg[i].first >> seg[i].second;
  vector<pair<int, int>> left(n), right(n);
  left[0].first = seg[0].first, left[0].second = seg[0].second;
  right[n - 1].first = seg[n - 1].first,
            right[n - 1].second = seg[n - 1].second;
  for (int i = 1; i < n; i++) {
    left[i].first =
        min(left[i - 1].second, max(left[i - 1].first, seg[i].first));
    left[i].second =
        max(left[i - 1].first, min(left[i - 1].second, seg[i].second));
  }
  for (int i = n - 2; i >= 0; i--) {
    right[i].first =
        min(right[i + 1].second, max(right[i + 1].first, seg[i].first));
    right[i].second =
        max(right[i + 1].first, min(right[i + 1].second, seg[i].second));
  }
  int ma = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    if (i == 0)
      chmax(ma, right[i + 1].second - right[i + 1].first);
    else if (i == n - 1)
      chmax(ma, left[i - 1].second - left[i - 1].first);
    else {
      l = left[i - 1].first, r = left[i - 1].second;
      chmax(l, right[i + 1].first);
      chmin(r, right[i + 1].second);
      chmax(ma, r - l);
    }
  }
  cout << ma << endl;
}
