#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  int l[n], r[n];
  int l1[n], r1[n];
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    l1[i] = l[i];
    r1[i] = r[i];
  }
  sort(l, l + n);
  sort(r, r + n);
  int ans = (r[0] - l[n - 1]);
  bool check = false;
  for (int i = 0; i < n; i++)
    if (l1[i] == l[n - 1] && r1[i] == r[0]) check = true;
  if (check)
    ans = max(ans, r[1] - l[n - 2]);
  else {
    ans = max(ans, r[1] - l[n - 1]);
    ans = max(ans, r[0] - l[n - 2]);
  }
  cout << max(0, ans) << '\n';
  return 0;
}
