#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 10;
int n;
int l[maxn];
int r[maxn];
map<pair<int, int>, int> f;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    f[pair<int, int>(l[i], r[i])] = 1;
  }
  sort(l + 1, l + n + 1);
  sort(r + 1, r + n + 1);
  int ans;
  if (f[pair<int, int>(l[n], r[1])]) {
    ans = r[2] - l[n - 1];
  } else {
    ans = max(r[2] - l[n], r[1] - l[n - 1]);
  }
  cout << max(ans, 0) << endl;
  return 0;
}
