#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  multiset<int, greater<int>> left;
  multiset<int> right;
  vector<pair<multiset<int, greater<int>>::iterator, multiset<int>::iterator>>
      v;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    auto l = left.insert(a);
    auto r = right.insert(b);
    v.push_back({l, r});
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    auto l = v[i].first;
    auto r = v[i].second;
    int l_val = *l;
    int r_val = *r;
    left.erase(l);
    right.erase(r);
    int inter_left = *left.begin();
    int inter_right = *right.begin();
    ans = max(ans, inter_right - inter_left);
    left.insert(l_val);
    right.insert(r_val);
  }
  cout << ans << endl;
}
