#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
multiset<int> a, b;
int L[maxn], R[maxn];
int main() {
  int n;
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> L[i] >> R[i];
    a.insert(L[i]);
    b.insert(R[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    a.erase(a.find(L[i]));
    b.erase(b.find(R[i]));
    ans = max(ans, *b.begin() - *a.rbegin());
    a.insert(L[i]);
    b.insert(R[i]);
  }
  cout << ans << endl;
  return 0;
}
