#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> l(n), r(n);
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
  }
  vector<int> maxPrefL(n), maxSuffL(n), minPrefR(n), minSuffR(n);
  maxPrefL[0] = l[0];
  minPrefR[0] = r[0];
  for (int i = 1; i < n; ++i) {
    maxPrefL[i] = max(l[i], maxPrefL[i - 1]);
    minPrefR[i] = min(r[i], minPrefR[i - 1]);
  }
  maxSuffL[n - 1] = l[n - 1];
  minSuffR[n - 1] = r[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    maxSuffL[i] = max(l[i], maxSuffL[i + 1]);
    minSuffR[i] = min(r[i], minSuffR[i + 1]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int left = max((i == 0 ? -100 : maxPrefL[i - 1]),
                   (i == n - 1 ? -100 : maxSuffL[i + 1]));
    int right = min((i == 0 ? 1000000009 : minPrefR[i - 1]),
                    (i == n - 1 ? 1000000009 : minSuffR[i + 1]));
    ans = max(ans, right - left);
  }
  cout << ans << '\n';
  return 0;
}
