#include <bits/stdc++.h>
using namespace std;
const long long N = 998244353;
long long fastExpo(long long aa, long long bb) {
  long long res = 1;
  while (bb > 0) {
    if (bb & 1) {
      res = (res * aa) % N;
    }
    aa = (aa * aa) % N;
    bb = bb >> 1;
  }
  return res;
}
long long mmi(long long nn) { return fastExpo(nn, N - 2); }
const long long ramramaramnamshamnam = 1e6 + 1;
long long facti[ramramaramnamshamnam];
void facto() {
  facti[0] = 1;
  for (long long i = 1; i < 1e6 + 1; i++) {
    facti[i] = (facti[i - 1] * i) % N;
  }
}
vector<long long> adj[100001];
long long vis[100001];
void dfs(long long node) {
  vis[node] = 1;
  for (auto child : adj[node]) {
    if (vis[child] == 0) dfs(child);
  }
}
void graph(long long vertex, long long edge) {
  for (long long i = 1; i <= vertex; i++) adj[i].clear();
  memset(vis, 0, sizeof vis);
  for (long long i = 1; i <= edge; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}
void solve() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > v;
  map<long long, long long> l;
  map<long long, long long> r;
  for (long long i = 0; i < n; i++) {
    long long uu, vv;
    cin >> uu >> vv;
    v.push_back({uu, vv});
    l[v[i].first]++;
    r[v[i].second]++;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    l[v[i].first]--;
    if (!(l[v[i].first])) l.erase(v[i].first);
    r[v[i].second]--;
    if (!(r[v[i].second])) r.erase(v[i].second);
    auto itf = l.rbegin();
    long long ll = itf->first;
    auto itb = r.begin();
    long long rr = (*itb).first;
    ans = max(ans, max((long long)0, rr - ll));
    l[v[i].first]++;
    r[v[i].second]++;
  }
  cout << ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(15);
  long long T = 1;
  while (T--) solve();
}
