#include <bits/stdc++.h>
using namespace std;
void fscpp() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fscpp();
  long long n;
  cin >> n;
  long long ct = 0;
  long long xm, ym;
  long long x, y;
  cin >> xm >> ym;
  vector<long long> vx(n), vy(n);
  vx[0] = xm;
  vy[0] = ym;
  for (long long int i = 1; i < n; i++) {
    cin >> x >> y;
    vx[i] = x;
    vy[i] = y;
  }
  vector<long long> mvx(vx), mvy(vy);
  sort(mvx.begin(), mvx.end());
  sort(mvy.begin(), mvy.end());
  long long max1 = mvx[n - 1], max2 = mvx[n - 2];
  long long min1 = mvy[0], min2 = mvy[1];
  long long len = min1 - max1;
  if (len < 0) len = 0;
  long long rx, ry;
  for (long long int i = 0; i < n; i++) {
    if (max1 == vx[i])
      rx = max2;
    else
      rx = max1;
    if (min1 == vy[i])
      ry = min2;
    else
      ry = min1;
    if (ry - rx > len) len = ry - rx;
  }
  len--;
  cout << len + 1;
  int p = 23;
  string s = std::bitset<63>(p).to_string();
  string h;
  string g;
  g = s;
  for (long long int i = s.size() - 2; i < s.size(); i++) h += s[i];
  y = h.size();
  s.clear();
  for (long long int i = 0; i < 31 - y; i++) {
    s += '1';
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  for (long long int i = 0; i < y; i++) {
    s += h[i];
  }
  y = std::bitset<63>(g).to_ulong();
  g.clear();
  if (g.size() != 0) cout << "yedhukku\n\t\n";
  reverse(s.begin(), s.end());
  return 0;
}
