#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dr4[] = {0, 1, -1, 0};
int dc4[] = {1, 0, 0, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, x, y;
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  x = -1;
  y = 1000000009;
  sort(v.begin(), v.end());
  pair<int, int> fr[n + 2], bk[n + 2];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int f = v[i].first;
    int s = v[i].second;
    x = f;
    y = min(y, s);
    fr[i + 1] = make_pair(x, y);
  }
  x = v[n - 1].first;
  y = 1000000009;
  for (int i = n - 1; i >= 0; i--) {
    int f = v[i].first;
    int s = v[i].second;
    y = min(y, s);
    bk[i + 1] = make_pair(x, y);
  }
  int mx = 0;
  fr[0] = make_pair(0, 1000000009);
  bk[n + 1] = make_pair(0, 1000000009);
  for (int i = 1; i <= n; i++) {
    int x1 = fr[i - 1].first, y1 = fr[i - 1].second, x2 = bk[i + 1].first,
        y2 = bk[i + 1].second;
    if (y1 < x1 || y2 < x2) continue;
    if (y1 < x2) continue;
    int mn = min(y1, y2);
    int mxx = max(x1, x2);
    mx = max(mx, mn - mxx);
  }
  cout << mx;
}
