#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
multiset<int> s, e;
int l[N], r[N];
int n, cnt;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    s.insert(-l[i]);
    e.insert(r[i]);
  }
  for (int i = 0; i < n; i++) {
    s.erase(s.find(-l[i]));
    e.erase(e.find(r[i]));
    int st = *s.begin();
    st = -st;
    int fi = *e.begin();
    cnt = max(cnt, fi - st);
    s.insert(-l[i]);
    e.insert(r[i]);
  }
  return cout << cnt, 0;
}
