#include <bits/stdc++.h>
using namespace std;
int ind = -1;
void binary_search(long long val, vector<long long> &v, int l, int r) {
  if (l > r) {
    return;
  }
  int mid = l + (r - l) / 2;
  if (v[mid] <= val) {
    ind = mid;
    binary_search(val, v, mid + 1, r);
  } else {
    binary_search(val, v, l, mid - 1);
  }
}
int main() {
  int n;
  cin >> n;
  vector<long long> x(n);
  vector<long long> y(n);
  vector<long long> dup_x(n);
  vector<long long> dup_y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    cin >> y[i];
  }
  dup_x = x;
  dup_y = y;
  sort(x.rbegin(), x.rend());
  sort(y.begin(), y.end());
  long long seg = 0;
  for (int i = 0; i < n; i++) {
    long long re_x = dup_x[i];
    long long re_y = dup_y[i];
    long long left = x[0];
    if (left == re_x) {
      left = x[1];
    }
    long long right = y[0];
    if (right == re_y) {
      right = y[1];
    }
    if (left <= right) {
      seg = max(seg, right - left);
    }
  }
  cout << seg << "\n";
  return 0;
}
