#include <bits/stdc++.h>
using namespace std;
const int N = 1001000;
multiset<int> a, b;
int l[N];
int r[N];
int main() {
  int n;
  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;
}
