#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printvec(vector<T>& vec) {
  for (long long int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int n;
  cin >> n;
  vector<long long int> prefleft(n + 2, 0);
  vector<long long int> sufright(n + 2, INT_MAX);
  vector<long long int> sufleft(n + 2, 0);
  vector<long long int> prefright(n + 2, INT_MAX);
  vector<pair<long long int, long long int> > inp;
  for (long long int i = 0; i < n; i++) {
    long long int l, r;
    cin >> l >> r;
    inp.push_back(make_pair(l, r));
  }
  for (long long int i = 0; i < n + 1; i++) {
    if (i == 0) {
      prefleft[i] = 0;
      prefright[i] = INT_MAX;
    } else {
      prefleft[i] = max(prefleft[i - 1], inp[i - 1].first);
      prefright[i] = min(prefright[i - 1], inp[i - 1].second);
    }
  }
  for (long long int i = n; i >= 1; i--) {
    if (i == n + 1) {
      sufleft[i] = 0;
      sufright[i] = INT_MAX;
    } else {
      sufleft[i] = max(sufleft[i + 1], inp[i - 1].first);
      sufright[i] = min(sufright[i + 1], inp[i - 1].second);
    }
  }
  long long int maxi = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int a = max(sufleft[i + 1], prefleft[i - 1]);
    long long int b = min(sufright[i + 1], prefright[i - 1]);
    if (b < a) {
      maxi = max(maxi, (long long int)0);
    } else {
      maxi = max(maxi, (b - a));
    }
  }
  cout << maxi << "\n";
}
