#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > range;
map<int, int> mp, rmp;
struct data {
  long long maxi, lazy;
};
data tree[3 * 800005];
void push_down(int n, int l, int r) {
  if (tree[n].lazy != 0) {
    tree[l].maxi += tree[n].lazy;
    tree[l].lazy += tree[n].lazy;
    tree[r].maxi += tree[n].lazy;
    tree[r].lazy += tree[n].lazy;
    tree[n].lazy = 0;
  }
}
void update(int n, int b, int e, int i, int j, int val) {
  if (b > j || e < i) return;
  if (b >= i && e <= j) {
    tree[n].maxi += val;
    tree[n].lazy += val;
    return;
  }
  int l = n * 2, r = l + 1, mid = (b + e) / 2;
  push_down(n, l, r);
  update(l, b, mid, i, j, val);
  update(r, mid + 1, e, i, j, val);
  tree[n].maxi = max(tree[l].maxi, tree[r].maxi);
}
long long queryl(int n, int b, int e, int val) {
  if (b == e) return b;
  int l = n * 2, r = l + 1, mid = (b + e) / 2;
  push_down(n, l, r);
  if (tree[l].maxi == val)
    return queryl(l, b, mid, val);
  else
    return queryl(r, mid + 1, e, val);
}
long long queryr(int n, int b, int e, int val) {
  if (b == e) return b;
  int l = n * 2, r = l + 1, mid = (b + e) / 2;
  push_down(n, l, r);
  if (tree[r].maxi == val)
    return queryr(r, mid + 1, e, val);
  else
    return queryr(l, b, mid, val);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    range.push_back(pair<int, int>(a, b));
    v.push_back(a);
    v.push_back(b);
  }
  sort(v.begin(), v.end());
  int cnt = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    int a = v[i];
    if (mp[a] == 0) {
      cnt++;
      mp[a] = cnt;
      rmp[cnt] = a;
    }
  }
  for (int i = 0; i < (int)range.size(); i++) {
    int a = mp[range[i].first];
    int b = mp[range[i].second];
    update(1, 1, cnt, a, b, 1);
  }
  long long ans = 0;
  for (int i = 0; i < (int)range.size(); i++) {
    int a = mp[range[i].first];
    int b = mp[range[i].second];
    update(1, 1, cnt, a, b, -1);
    if (tree[1].maxi == n - 1) {
      int x = queryl(1, 1, cnt, n - 1);
      int y = queryr(1, 1, cnt, n - 1);
      x = rmp[x];
      y = rmp[y];
      long long temp = y - x;
      ans = max(ans, temp);
    }
    update(1, 1, cnt, a, b, 1);
  }
  printf("%lld\n", ans);
  return 0;
}
