#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int ar[300001], ar2[300001], ar3[300001], ar4[300001], lol;
int main() {
  long long i, j, a, b, x, n, y, ck, t, r, ans, rem, cnt, lo, hi, sum, cs = 1;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> ar[i] >> ar2[i], ar3[i] = ar[i], ar4[i] = ar2[i];
  sort(ar, ar + n), sort(ar2, ar2 + n);
  ans = 0;
  for (i = 0; i < n; i++) {
    a = ar[n - 1];
    b = ar2[0];
    if (ar[n - 1] == ar3[i]) a = ar[n - 2];
    if (ar2[0] == ar4[i]) b = ar2[1];
    ans = max(ans, b - a);
  }
  cout << ans;
}
