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