#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> lc, rc;
vector<pair<int, int>> stuff;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    stuff.emplace_back(l, r);
    lc[l]++;
    rc[r]++;
  }
  int ans = max(0, rc.begin()->first - lc.rbegin()->first);
  for (int i = 0; i < n; i++) {
    int l, r;
    l = stuff[i].first;
    r = stuff[i].second;
    lc[l]--;
    if (lc[l] == 0) lc.erase(lc.find(l));
    rc[r]--;
    if (rc[r] == 0) rc.erase(rc.find(r));
    ans = max(ans, rc.begin()->first - lc.rbegin()->first);
    stuff.emplace_back(l, r);
    lc[l]++;
    rc[r]++;
  }
  cout << ans << endl;
}
