#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, l;
  cin >> n;
  multiset<pair<int, int> > s;
  int arr[n + 1][2];
  for (i = 1; i <= n; i++) {
    cin >> arr[i][0] >> arr[i][1];
    s.insert(make_pair(arr[i][0], -i));
    s.insert(make_pair(arr[i][1], i));
  }
  int flag = 0;
  int kl = 0;
  int bl = 0;
  int count = 0;
  for (auto it = s.begin(); it != s.end(); it++) {
    if ((*it).second < 0) {
      count++;
      if (count == n) {
        if (bl == 1) {
          if (n == 2) {
            auto jt = it;
            jt++;
            auto lt = it;
            lt--;
            auto kt = lt;
            kt--;
            i = ((*jt).first) - ((*it).first);
            j = ((*lt).first) - ((*kt).first);
            cout << max(i, j);
            return 0;
          }
          auto jt = it;
          jt++;
          cout << ((*jt).first) - ((*it).first);
          return 0;
        } else if (bl == 0) {
          auto jt = it;
          jt++;
          auto kt = jt;
          kt++;
          auto lt = it;
          lt--;
          if ((*it).second == (-(*jt).second)) {
            cout << ((*kt).first) - ((*lt).first);
            return 0;
          } else {
            i = ((*jt).first) - ((*lt).first);
            j = ((*kt).first) - ((*it).first);
            cout << max(i, j);
            return 0;
          }
        }
      }
    }
    if ((*it).second > 0) bl++;
  }
  count = 0;
  bl = 0;
  for (auto it = s.rbegin(); it != s.rend(); it++) {
    if ((*it).second < 0) bl++;
    if ((*it).second > 0) {
      count++;
      if (count == n) {
        if (bl == 1) {
          auto lt = it;
          lt++;
          cout << ((*it).first) - ((*lt).first);
          return 0;
        }
      }
    }
  }
  cout << 0;
  return 0;
}
