#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  std::cin >> n;
  int max = -1;
  int min = -1;
  std::vector<int> l, r;
  for (int i = 0; i < n; ++i) {
    int x, y;
    std::cin >> x >> y;
    l.push_back(x);
    r.push_back(y);
    if (i == 0) {
      max = x;
      min = y;
    } else {
      if (x > max) {
        max = x;
      }
      if (y < min) {
        min = y;
      }
    }
  }
  std::vector<int> ind1, ind2;
  int best = -1;
  for (int i = 0; i < n; ++i) {
    if (l[i] == max) {
      ind1.push_back(i);
      if (r[i] == min) {
        best = i;
      }
    } else {
      if (r[i] == min) {
        ind2.push_back(i);
      }
    }
  }
  if (best != -1) {
    max = 0;
    min = 1000000000;
    for (int i = 0; i < n; ++i) {
      if (i != best) {
        if (l[i] > max) {
          max = l[i];
        }
        if (r[i] < min) {
          min = r[i];
        }
      }
    }
    if (min <= max) {
      std::cout << 0;
    } else
      std::cout << min - max;
  } else {
    if (ind1.size() > 1 and ind2.size() > 1) {
      if (min <= max) {
        std::cout << 0;
      } else
        std::cout << min - max;
    } else {
      int max2 = 0;
      int min2 = 1000000000;
      for (int i = 0; i < n; ++i) {
        if (i != best) {
          if (l[i] > max2 and i != ind1[0]) {
            max2 = l[i];
          }
          if (r[i] < min2 and i != ind2[0]) {
            min2 = r[i];
          }
        }
      }
      int t1 = min - max2;
      int t2 = min2 - max;
      if (t1 > t2) {
        if (t1 < 0)
          std::cout << 0;
        else
          std::cout << t1;
      } else {
        if (t2 < 0)
          std::cout << 0;
        else
          std::cout << t2;
      }
    }
  }
}
