#include <bits/stdc++.h>
using namespace std;
const long long int N = 3e5 + 5;
long long int n;
long long int l[N], r[N];
multiset<long long int> lft, rgt;
int main() {
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    lft.insert(l[i]);
    rgt.insert(r[i]);
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    lft.erase(lft.find(l[i]));
    rgt.erase(rgt.find(r[i]));
    ans = max(ans, *rgt.begin() - *lft.rbegin());
    lft.insert(l[i]);
    rgt.insert(r[i]);
  }
  cout << ans << endl;
}
