#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
void Draganov47(string click) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void submit() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  multiset<int> x, y;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    x.insert(a[i].first);
    y.insert(a[i].second);
  }
  int best = 0;
  for (int i = 0; i < n; i++) {
    x.erase(x.lower_bound(a[i].first));
    y.erase(y.lower_bound(a[i].second));
    best = max(best, *y.begin() - *prev(x.end()));
    x.insert(a[i].first);
    y.insert(a[i].second);
  }
  cout << best;
}
int main() {
  Draganov47("vk.com/gotovseros");
  int T = 1;
  for (int c = 1; c <= T; c++) {
    submit();
  }
  return 0;
}
