#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
  return '"' + s + '"';
}
string to_string(const char* s) {
  return to_string((string) s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int min_b = *min_element(b.begin(), b.end());
  int max_a = *max_element(a.begin(), a.end());
  int ans = 0;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++) {
    p[i] = make_pair(min_b - a[i] + 1, b[i] - max_a + 1);
    p[i].second*=-1; 
  }
  sort(p.begin(), p.end());
  //debug(p);
  int m2 = (int) 1.01e9;
  //for(int i=0;i<n;i++)
  //{
  	//cout<<p[i].first<<" "<<p[i].second<<endl;
  //}
  for (int i = 0; i < n - 1; i++) {
  	p[i].second*=-1;
    m2 = min(m2, p[i].second);
    ans = max(ans, p[i + 1].first + m2);
    //cout<<p[i+1].first+m2<<" "<<ans<<endl;
  }
  //分为两堆放，一堆里面有Lmax，一堆里面有Rmin，最终的结果肯定是a里面的某个数，b里面的某个数，且他们不在一行
  //那么，假定a（i+1）是被选取的那个数，那么它这个集合里面只能是比a（i+1）大的数，即排序之后 在它后面的数
  //那么 在他前面的数 为了满足那个假设，只能放到另一个集合里面，计算前面出现过的最小值即可。比a（i+1）大的那些数的b
  //不管是否放在前面 也无法使前面的最小值变大，甚至可能让它们变小，所以后面的那些值放在和a（i+1）一个集合里面较优。 
  for (int i = 0; i < n; i++) {
    int cur = b[i] - a[i] + 1;
    cur += max(0, min_b - max_a + 1);
    ans = max(ans, cur);
  }
  cout << ans << '\n';
  return 0;
}
/*
4
4 9
2 5
1 5
1 8


*/

Measured memory_bytes: 1792