#include <bits/stdc++.h>
const int N = 3e5 + 10;
int n;
int l[N], r[N];
std::multiset<int> left, right;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l[i], &r[i]);
    left.insert(l[i]);
    right.insert(r[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    left.erase(left.find(l[i]));
    right.erase(right.find(r[i]));
    ans = std::max(ans, *right.begin() - *left.rbegin());
    left.insert(l[i]);
    right.insert(r[i]);
  }
  printf("%d\n", ans);
  return 0;
}
