#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> p[1000000];
void max_min(int &mx, int &mxi, int &mn, int &mni, int xi, int yi) {
  for (int i = 0; i < n; ++i) {
    int x, y;
    tie(x, y) = p[i];
    if (x > mx && i != xi) {
      mx = x;
      mxi = i;
    }
    if (y < mn && i != yi) {
      mn = y;
      mni = i;
    }
  }
}
int main() {
  int maxOne, maxTwo, minOne, minTwo;
  int maxOneIndex, maxTwoIndex, minOneIndex, minTwoIndex;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> p[i].first;
    cin >> p[i].second;
  }
  maxOne = INT_MIN, minOne = INT_MAX;
  max_min(maxOne, maxOneIndex, minOne, minOneIndex, -1, -1);
  maxTwo = INT_MIN, minTwo = INT_MAX;
  max_min(maxTwo, maxTwoIndex, minTwo, minTwoIndex, maxOneIndex, minOneIndex);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int start = maxOne, end = minOne;
    if (maxOneIndex == i) {
      start = maxTwo;
    }
    if (minOneIndex == i) {
      end = minTwo;
    }
    ans = max(ans, end - start);
  }
  cout << ans << endl;
}
