#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int l[300010];
int r[300010];
multiset<int> a, b;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
    scanf("%d", &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]);
  }
  printf("%d\n", ans);
}
