#include <bits/stdc++.h>
const long long M = 1e9 + 7;
const long long N = 2e5 + 5;
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n][2];
  long long b[n], c[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1];
  }
  for (int i = 0; i < n; i++) {
    b[i] = a[i][0];
    c[i] = a[i][1];
  }
  sort(b, b + n);
  sort(c, c + n);
  long long mn1 = c[0], mn2 = c[1], mx1 = b[n - 1], mx2 = b[n - 2];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i][0] == mx1 && a[i][1] == mn1) {
      ans = max(ans, mn2 - mx2);
    }
    if (a[i][0] == mx1) {
      ans = max(ans, mn1 - mx2);
    } else if (a[i][1] == mn1) {
      ans = max(ans, mn2 - mx1);
    } else {
      ans = max(ans, mn1 - mx1);
    }
  }
  cout << ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
