#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, temp1, temp2, fin;
  cin >> n;
  pair<long long, long long> a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + n, greater<pair<long long, long long> >());
  long long its = 0, nits = 0, best = a[0].first, mini = a[0].second,
            index1 = 0, index2 = 0, index3 = 0, index4 = 0;
  long long best2 = best;
  for (long long i = 0; i < n - 1; i++) {
    if (a[i].second < mini) {
      mini = a[i].second;
      index2 = i;
    }
    if (a[i].first == best) index1 = i;
    if (a[i].first > a[i + 1].second) {
      nits++;
      index3 = i, index4 = i + 1;
      if (nits == 2) {
        cout << "0\n";
        return 0;
      }
    } else {
      its++;
    }
  }
  if (a[n - 1].second < mini) {
    mini = a[n - 1].second;
    index2 = n - 1;
  }
  if (a[n - 1].first == best) index1 = n - 1;
  if (nits == 0) {
    long long ans1, ans2;
    long long temp1 = -1, temp2 = INT_MAX;
    for (long long i = 0; i < n; i++) {
      if (i != index1 && a[i].first > temp1) {
        temp1 = a[i].first;
      }
      if (i != index1 && a[i].second < temp2) {
        temp2 = a[i].second;
      }
    }
    ans1 = temp2 - temp1;
    temp1 = -1, temp2 = INT_MAX;
    for (long long i = 0; i < n; i++) {
      if (i != index2 && a[i].first > temp1) {
        temp1 = a[i].first;
      }
      if (i != index2 && a[i].second < temp2) {
        temp2 = a[i].second;
      }
    }
    ans2 = temp2 - temp1;
    fin = max(ans1, ans2);
    if (fin < 0) {
      cout << "0\n";
    } else {
      cout << fin << "\n";
    }
  } else if (nits == 1) {
    long long ans3, ans4;
    long long temp3 = -1, temp4 = INT_MAX;
    for (long long i = 0; i < n; i++) {
      if (i != index3 && a[i].first > temp3) {
        temp3 = a[i].first;
      }
      if (i != index3 && a[i].second < temp4) {
        temp4 = a[i].second;
      }
    }
    ans3 = temp4 - temp3;
    temp3 = -1, temp4 = INT_MAX;
    for (long long i = 0; i < n; i++) {
      if (i != index4 && a[i].first > temp3) {
        temp3 = a[i].first;
      }
      if (i != index4 && a[i].second < temp4) {
        temp4 = a[i].second;
      }
    }
    ans4 = temp4 - temp3;
    fin = max(ans3, ans4);
    if (fin < 0) {
      cout << "0\n";
    } else {
      cout << fin << "\n";
    }
  }
  return 0;
}
