#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifdef STOPIT
#define debug(...) 0
#else
#define debug(...)\
do {\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;\
} while (false)
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& tuple_input_impl(std::istream& os, Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { (void)std::initializer_list<int>{((void)(os >> std::get< Inds >(tuple)), 0)...}; return os; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& operator>> (std::istream& os, Tuple<Args...>& tuple)
  { return tuple_input_impl(os, tuple, std::index_sequence_for<Args...>()); }

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& tuple_output_impl(std::ostream& os, const Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { os << "("; (void)std::initializer_list<int>{((void)(os << (Inds > 0 ? "," : "") << std::get< Inds >(tuple)), 0)...}; return os << ")"; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& operator<< (std::ostream& os, const Tuple<Args...>& tuple)
 { return tuple_output_impl(os, tuple, std::index_sequence_for<Args...>()); }

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector< int > a;
  std::vector< std::pair< int, int > > pairs(n);
  rep(i, 0, n) {
    int x, y; std::cin >> x >> y;
    x--;
    pairs.at(i) = {x, y};
    a.emplace_back(x);
    a.emplace_back(y);
  }
  std::sort(all(a));
  a.resize(std::unique(all(a)) - a.begin());
  auto rev = [&] (int x) {
    auto lb = std::lower_bound(all(a), x);
    assert(*lb == x);
    return lb - a.begin();
  };
  for (auto & pair : pairs) {
    pair.first = rev(pair.first);
    pair.second = rev(pair.second);
  }

  int R = 1e9;
  for (auto pair : pairs) {
    cmn(R, pair.second);
  }

  int ans = 0;
  std::vector< std::pair< int, int > > red = pairs;
  std::vector< std::pair< int, int > > blue;
  int blueL = 0, blueR = 1e9;
  std::sort(all(red));
  for (int L = R - 1; 0 <= L; L--) {
    while (!red.empty()) {
      int l, r; std::tie(l, r) = red.back();
      if (l <= L) break;
      blue.emplace_back(l, r);
      cmx(blueL, l);
      cmn(blueR, r);
      red.pop_back();
    }
    if (red.empty()) break;
    if (blue.empty()) continue;
    debug(red);
    debug(blue);

    int x = a.at(R) - a.at(L);
    int y = std::max(0, a.at(blueR) - a.at(blueL));
    cmx(ans, x + y);
  }

  std::sort(all(pairs));
  std::vector< int > len(n);
  rep(i, 0, n) {
    len.at(i) = a.at(pairs.at(i).second) - a.at(pairs.at(i).first);
  }
  debug(pairs);
  debug(len);

  auto make = [&] {
    std::vector< int > l0(n), r0(n);
    l0.at(0) = 0;
    r0.at(0) = 1e9;
    rep(i, 0, n-1) {
      l0.at(i + 1) = std::max(l0.at(i), a.at(pairs.at(i).first));
      r0.at(i + 1) = std::min(r0.at(i), a.at(pairs.at(i).second));
    }
    return std::make_pair(l0, r0);
  };
  std::vector< int > l0(n), r0(n), l1(n), r1(n);
  std::tie(l0, r0) = make();
  std::reverse(all(pairs));
  std::tie(l1, r1) = make();
  std::reverse(all(l1));
  std::reverse(all(r1));

  std::vector< int > l2(n), r2(n);
  rep(i, 0, n) {
    l2.at(i) = std::max(l0.at(i), l1.at(i));
    r2.at(i) = std::min(r0.at(i), r1.at(i));
    int z = std::max(0, r2.at(i) - l2.at(i));
    debug(len.at(i), z);
    cmx(ans, len.at(i) + z);
  }
  debug(l0, r0, l1, r1, l2, r2);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 6900