#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > arr;
  priority_queue<int> left, right;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a;
    left.push(a);
    cin >> b;
    right.push(-b);
    arr.push_back(make_pair(a, b));
  }
  int max = -left.top() - right.top();
  if (max < 0) max = 0;
  for (int i = 0; i < n; ++i) {
    if (arr[i].first == left.top()) {
      left.pop();
      if (arr[i].second == -right.top()) {
        right.pop();
        if (-left.top() - right.top() > max) max = -left.top() - right.top();
        right.push(-arr[i].second);
        left.push(arr[i].first);
      } else {
        if (-left.top() - right.top() > max) max = -left.top() - right.top();
        left.push(arr[i].first);
      }
    } else if (arr[i].second == -right.top()) {
      right.pop();
      if (-left.top() - right.top() > max) max = -left.top() - right.top();
      right.push(-arr[i].second);
    }
  }
  cout << max;
  return 0;
}
