#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 1;
const int MAXN = (int)5001;
int solve(vector<pair<int, int> > sg, int pos) {
  sg.erase(sg.begin() + pos);
  int mx = sg[0].first, mn = sg[0].second;
  for (int i = (1); i < (int)(sg.size()); i++) {
    if (sg[i].first > mn || sg[i].second < mx) return 0;
    mx = max(mx, sg[i].first);
    mn = min(mn, sg[i].second);
  }
  return abs(mx - mn);
}
bool comp1(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first == b.first) ? (a.second - a.first > b.second - b.first)
                              : (a.first < b.first);
}
bool comp2(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second == b.second) ? (a.second - a.first < b.second - b.first)
                                : (a.second < b.second);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x, y;
  cin >> n;
  vector<pair<int, int> > sgm;
  for (int i = (0); i < (int)(n); i++) {
    cin >> x >> y;
    sgm.push_back(make_pair(x, y));
  }
  sort((sgm).begin(), (sgm).end(), comp1);
  x = solve(sgm, n - 1);
  sort((sgm).begin(), (sgm).end(), comp2);
  cout << max(x, solve(sgm, 0));
}
