#include <bits/stdc++.h>
using namespace std;
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > p;
  vector<long long int> another;
  for (long long int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    p.push_back(make_pair(a, b));
    another.push_back(b);
  }
  sort((p).begin(), (p).end());
  sort((another).begin(), (another).end());
  long long int x = another[0];
  long long int y = another[1];
  long long int ans = 0;
  for (long long int i = 0; i < p.size(); i++) {
    if (i != p.size() - 1) {
      if (p[i].second == x) {
        ans = max(ans, (long long int)(y - p[p.size() - 1].first));
      } else {
        ans = max(ans, (long long int)(x - p[p.size() - 1].first));
      }
    } else {
      if (p[i].second == x) {
        ans = max(ans, (long long int)(y - p[p.size() - 2].first));
      } else {
        ans = max(ans, (long long int)(x - p[p.size() - 2].first));
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
