//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

pair<int, int> intersect(const pair<int, int> &lhs, const pair<int, int> &rhs) {
    return {max(lhs.first, rhs.first), min(lhs.second, rhs.second)};
}

int length(const pair<int, int> &interval) {
    if (interval.first > interval.second) {
        return 0;
    } else {
        return interval.second - interval.first + 1;
    }
}

int main() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> seg(n);
    pair<int, int> left = {0, 1e9}, right = {0, 1e9};
    for (auto &i:seg) {
        cin >> i.first >> i.second;
        if (i.first > right.first) {
            right = i;
        }
        if (i.second < left.second) {
            left = i;
        }
    }
    for (int i = 0; i < seg.size(); ++i) {
        if (seg[i] == left) {
            seg.erase(begin(seg) + i);
            i--;
            if (seg.empty()) {
                break;
            } else {
                continue;
            }
        }
        if (seg[i] == right) {
            seg.erase(begin(seg) + i);
            i--;
            if (seg.empty()) {
                break;
            } else {
                continue;
            }
        }
    }
    int ans = 0;
    if (!seg.empty()) {
        pair<int, int> inter = {0, -1};
        for (const auto &i:seg) {
            if (length(i) > length(inter)) {
                inter = i;
            }
        }
        ans = length(inter) + length(intersect(left, right));
    } else {
        ans = length(left) + length(right);
    }
    if (!seg.empty()) {
        sort(begin(seg), end(seg));
        vector<int> suf(seg.size());
        suf[seg.size() - 1] = seg[seg.size() - 1].second;
        for (int i = static_cast<int>(seg.size()) - 2; i >= 0; --i) {
            suf[i] = min(suf[i + 1], seg[i].second);
        }
        for (int i = 0; i < seg.size(); ++i) {
            int first = length(intersect(seg[i], left)),
                second = i + 1 < seg.size() ? length(intersect({right.first, suf[i + 1]}, right)) : length(right);
            ans = max(ans, first + second);
        }
        ans = max(ans, length(left) + length(intersect({right.first, suf[0]}, right)));
    }
    cout << ans;
    return 0;
}