#include <bits/stdc++.h>
using namespace std;
const long long int inf = 0x3f3f3f3f3f3f3f3fll;
const int maxx = 10000000;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long int> l, r;
  pair<long long int, long long int> p[n + 2];
  for (int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    l.push_back(x);
    r.push_back(y);
    p[i].first = x;
    p[i].second = y;
  }
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  sort(r.begin(), r.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int left = l[0], right = r[0];
    if (p[i].first == l[0]) left = l[1];
    if (p[i].second == r[0]) right = r[1];
    if (right < left)
      continue;
    else
      ans = max(ans, (right - left));
  }
  cout << ans << endl;
  return 0;
}
