#include <bits/stdc++.h>
const int N = 300005;
using namespace std;
multiset<int> a, b;
int line1[N], line2[N];
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &line1[i], &line2[i]);
    a.insert(line1[i]);
    b.insert(line2[i]);
  }
  for (int i = 1; i <= n; i++) {
    a.erase(a.find(line1[i]));
    b.erase(b.find(line2[i]));
    ans = max(ans, *(b.begin()) - *(a.rbegin()));
    a.insert(line1[i]);
    b.insert(line2[i]);
  }
  printf("%d\n", ans);
  return 0;
}
