#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> pr[300005];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> pr[i].first >> pr[i].second;
  }
  sort(pr + 1, pr + 1 + n);
  long long ans = 0;
  long long mx = 0, mn = 1e9;
  for (int i = 1; i < n; i++) {
    mx = max(mx, pr[i].first);
    mn = min(mn, pr[i].second);
  }
  ans = max(ans, mn - mx);
  for (int i = 1; i <= n; i++) {
    long long p = pr[i].first;
    long long q = pr[i].second;
    pr[i].first = q;
    pr[i].second = -p;
  }
  sort(pr + 1, pr + 1 + n);
  mx = 0, mn = 1e9;
  for (int i = 2; i <= n; i++) {
    mx = max(mx, -pr[i].second);
    mn = min(mn, pr[i].first);
  }
  ans = max(ans, mn - mx);
  cout << ans << "\n";
  return 0;
}
