#include <bits/stdc++.h>
const int Inf = 2e9;
long long LINF = (long long)4e18;
using namespace std;
long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> l(n), r(n);
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].first >> v[i].second;
    l[i] = v[i].first;
    r[i] = v[i].second;
  }
  sort(l.rbegin(), l.rend());
  sort(r.begin(), r.end());
  int ans = max(0, r[0] - l[0]);
  for (int i = 0; i < n; ++i) {
    int a = l[0], b = r[0];
    if (v[i].first == l[0]) a = l[1];
    if (v[i].second == r[0]) b = r[1];
    ans = max(ans, max(0, b - a));
  }
  cout << ans;
  return 0;
}
