#include <bits/stdc++.h>
using namespace std;
class Segment {
 public:
  Segment(){};
  Segment(int left, int right) : l(left), r(right){};
  int l, r;
};
int main() {
  int n;
  cin >> n;
  Segment segments[n];
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l;
    cin >> r;
    segments[i].l = l;
    segments[i].r = r;
  }
  int maxl = segments[0].l;
  int maxl_i = 0;
  int minr = segments[0].r;
  int minr_i = 0;
  for (int i = 1; i < n; i++) {
    if (segments[i].l >= maxl) {
      maxl = segments[i].l;
      maxl_i = i;
    }
    if (segments[i].r <= minr) {
      minr = segments[i].r;
      minr_i = i;
    }
  }
  int maxl2 = INT_MIN;
  int minr2 = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (segments[i].l >= maxl2 && i != maxl_i) {
      maxl2 = segments[i].l;
    }
    if (segments[i].r <= minr2 && i != minr_i) {
      minr2 = segments[i].r;
    }
  }
  int result = 0;
  for (int i = 0; i < n; i++) {
    int max = maxl;
    int min = minr;
    if (segments[i].l == maxl) {
      max = maxl2;
    }
    if (segments[i].r == minr) {
      min = minr2;
    }
    if (min - max >= result) {
      result = min - max;
    }
  }
  std::cout << result << '\n';
}
