#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9;
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) scanf("%d %d", &a[i].first, &a[i].second);
  int res = 0;
  int idx = 0;
  for (int i = 1; i < n; i++) {
    if (a[i].first > a[idx].first)
      idx = i;
    else if (a[i].first == a[idx].first && a[i].second < a[idx].second)
      idx = i;
  }
  int L = -1, R = (int)2e9;
  for (int i = 0; i < n; i++) {
    if (i == idx) continue;
    if (a[i].first > L) L = a[i].first;
    if (a[i].second < R) R = a[i].second;
  }
  res = max(res, R - L);
  idx = 0;
  for (int i = 1; i < n; i++) {
    if (a[i].second < a[idx].second)
      idx = i;
    else if (a[i].second == a[idx].second && a[i].first > a[idx].first)
      idx = i;
  }
  L = -1, R = (int)2e9;
  for (int i = 0; i < n; i++) {
    if (i == idx) continue;
    if (a[i].first > L) L = a[i].first;
    if (a[i].second < R) R = a[i].second;
  }
  res = max(res, R - L);
  printf("%d\n", res);
  return 0;
}
