#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
class Range {
    using T = long long;
    class Iterator {
        T val, step, diff;
    public:
        Iterator(T v, T s, T d): val(v), step(s), diff(d) {}
        T operator*() { return val + diff; }
        bool operator!=(const Iterator &itr) { return step > 0 ? val < itr.val : val > itr.val; }
        Iterator operator++() { val += step; return *this; }
    };
    Iterator _begin, _end;
public:
    Range(T b, T e, T s, T d): _begin(b, s, d), _end(e, s, d) {
        if (s < 0) { _begin = Iterator(e - 1, s, d); _end = Iterator(b - 1, s, d); }
    }
    Range(T b, T e, T s): Range(b, e, s, 0) {}
    Range(T b, T e): Range(b, e, 1, 0) {}
    Range(T e): Range(0, e, 1, 0) {}
    Iterator begin() { return _begin; }
    Iterator end() { return _end; }
};
// clang-format on

#include <stack>
#include <functional>
#include <utility>
template<typename T>
class SWAG {
    using P = pair<T, T>;  // raw_data, fold_all
    using Func = function<T(T, T)>;
    stack<P> front_stack, back_stack;
    Func func;

public:
    SWAG(Func _func)
        : func(_func) {}
    void push(T ele) {
        if (back_stack.empty()) {
            back_stack.emplace(ele, ele);
        } else {
            T lst = back_stack.top().second;
            back_stack.emplace(ele, func(lst, ele));
        }
    }
    void pop() {
        if (front_stack.empty()) {
            T fold = back_stack.top().first;
            front_stack.emplace(fold, fold);
            back_stack.pop();
            while (back_stack.size()) {
                T ele = back_stack.top().first;
                front_stack.emplace(ele, fold = func(ele, fold));
                back_stack.pop();
            }
        }
        front_stack.pop();
    }
    T fold_all() {
        if (front_stack.empty()) {
            return back_stack.top().second;
        } else if (back_stack.empty()) {
            return front_stack.top().second;
        } else {
            return func(front_stack.top().second, back_stack.top().second);
        }
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<P> v(n);
    for (auto &vv : v) {
        cin, vv.first, vv.second;
        vv.second += 1;
    }
    sort(v.begin(), v.end());
    auto MIN = [](ll a, ll b) {
        return min(a, b);
    };
    SWAG<ll> swag(MIN);
    for (auto i : Range(0, n - 2, -1)) {
        swag.push(v[i].second);
    }

    ll ans = 0;
    ll L1 = v.back().first;
    ll R1 = v.back().second;
    for (ll i : Range(0, n - 1, -1)) {
        ll L2 = v[i].first;
        ll R2 = v[i].second;
        ll Rt = 1LL << 60;
        if (i != 0) {
            Rt = swag.fold_all();
            swag.pop();
        }
        chmax(ans, max(0LL, R1 - L1) + max(0LL, min(R2, Rt) - L2));
        chmax(ans, max(0LL, min(R1, Rt) - L1) + max(0LL, R2 - L2));
        chmin(R1, v[i].second);
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3584