#include <bits/stdc++.h>
using namespace std;
pair<int, int> Inter(pair<int, int> a, pair<int, int> b) {
  int l1 = a.first;
  int r1 = a.second;
  int l2 = b.first;
  int r2 = b.second;
  pair<int, int> p;
  if (l2 < l1 && r2 <= l1) {
    if (r2 == l1) {
      p = {l1, l1};
    } else {
      p = {-1, -1};
    }
  } else if (l2 < l1 && r2 > l1 && r2 <= r1) {
    p = {l1, r2};
  } else if (l2 < l1 && r2 > r1) {
    p = {l1, r1};
  } else if (l2 >= l1 && r2 <= r1) {
    p = {l2, r2};
  } else if (l2 >= l1 && l2 < r1 && r2 > r1) {
    p = {l2, r1};
  } else if (l2 >= r1) {
    if (l2 == r1) {
      p = {l2, l2};
    } else {
      p = {-1, -1};
    }
  }
  return p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) {
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      v.push_back({a, b});
    }
    vector<pair<int, int> > fwd;
    vector<pair<int, int> > bwd(n);
    fwd.push_back(v[0]);
    for (int i = 1; i < n; i++) {
      pair<int, int> res = Inter(fwd[i - 1], v[i]);
      fwd.push_back(res);
    }
    bwd[n - 1] = v[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      pair<int, int> res = Inter(bwd[i + 1], v[i]);
      bwd[i] = res;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        int len = bwd[1].second - bwd[1].first;
        ans = max(len, ans);
      } else if (i == n - 1) {
        int len = fwd[n - 2].second - fwd[n - 2].first;
        ans = max(len, ans);
      } else {
        pair<int, int> res = Inter(fwd[i - 1], bwd[i + 1]);
        int len = res.second - res.first;
        ans = max(len, ans);
      }
    }
    cout << ans;
  }
  return 0;
}
