#include <bits/stdc++.h>
class TaskC {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    std::vector<int> lefts(n);
    std::vector<int> rights(n);
    int maxLeft = 0;
    int minRight = 1000000000;
    int maxLeftMinRight = 1000000000;
    int minRightMaxLeft = 0;
    int maxLeftIndex = 0;
    int minRightIndex = 0;
    for (int i = 0; i < n; ++i) {
      in >> lefts[i] >> rights[i];
      if (lefts[i] > maxLeft ||
          (lefts[i] == maxLeft && rights[i] < maxLeftMinRight)) {
        maxLeftIndex = i;
        maxLeft = lefts[i];
        maxLeftMinRight = rights[i];
      }
      if (rights[i] < minRight ||
          (rights[i] == minRight && lefts[i] > minRightMaxLeft)) {
        minRightIndex = i;
        minRight = rights[i];
        minRightMaxLeft = lefts[i];
      }
    }
    int best = 0;
    std::pair<int, int> interval(0, 1000000000);
    for (int i = 0; i < n; ++i) {
      if (i == maxLeftIndex) {
        continue;
      }
      interval = std::pair<int, int>(std::max(interval.first, lefts[i]),
                                     std::min(interval.second, rights[i]));
    }
    best = std::max(best, interval.second - interval.first);
    interval = std::pair<int, int>(0, 1000000000);
    for (int i = 0; i < n; ++i) {
      if (i == minRightIndex) {
        continue;
      }
      interval = std::pair<int, int>(std::max(interval.first, lefts[i]),
                                     std::min(interval.second, rights[i]));
    }
    best = std::max(best, interval.second - interval.first);
    out << best;
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  TaskC solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
