#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
string str, ans, rafi, chk;
map<int, int> maap;
queue<int> q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  ll n, m, i, cnt1 = 0, cnt2 = 0, cnt = 0, even = 0, odd = 0, len, k, r, l, p,
              z = 0, x = 0, y = 0, x1, y1, x2, y2, flag = 0, sum = 0,
              tottal = 0;
  ll a = 0, b = 0, c = 0, d, zero = 0, fst = 0, null = 0, snd = 0, lst = 0,
     rone = 0, one = 0, pos = 0, neg = 0, mn = INT_MAX, mx = INT_MIN;
  char ch;
  int h1, h2, m1, m2, h, time;
  string str, store = "";
  cin >> n;
  vector<int> startp(n), endp(n);
  for (int i = 0; i < n; i++) {
    cin >> startp[i] >> endp[i];
    maap[startp[i]] = endp[i];
  }
  sort(startp.begin(), startp.end());
  sort(endp.begin(), endp.end());
  int ans = max({0, (endp[0] - startp[n - 2]), (endp[1] - startp[n - 1])});
  if (maap[startp[n - 1]] == endp[0]) {
    ans = max(ans, endp[1] - startp[n - 2]);
  }
  cout << ans << endl;
  return 0;
}
