#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
multiset<int> l, r;
int n, x[maxn], y[maxn], ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    l.insert(x[i]);
    r.insert(y[i]);
  }
  for (int i = 1; i <= n; i++) {
    l.erase(l.find(x[i]));
    r.erase(r.find(y[i]));
    ans = max(ans, *r.begin() - *l.rbegin());
    l.insert(x[i]);
    r.insert(y[i]);
  }
  printf("%d", ans);
  return 0;
}
