#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;

    P l[112345], r[112345];

    cin >> n;
    REP(i, n)
    {
        int a, b;
        cin >> a >> b;

        l[i] = {a, b};
        r[i] = {-b, -a};
    }

    sort(l, l + n);
    sort(r, r + n);

    ll res = 0;

    {
        //L

        int up[112345];
        int down[112345];

        memset(up, 0, sizeof(up));
        memset(down, 0, sizeof(down));

        down[0] = l[0].second - l[0].first + 1;

        int mi = l[0].first;
        int ma = l[0].second;

        for (int i = 1; i < n; i++)
        {
            if (l[i].second < mi || ma < l[i].first)
                break;

            mi = l[i].first;
            ma = min(ma, l[i].second);

            down[i] = ma - mi + 1;
        }

        up[n - 1] = l[n - 1].second - l[n - 1].first + 1;

        mi = l[n - 1].first;
        ma = l[n - 1].second;

        for (int i = n - 2; i >= 0; i--)
        {
            if (l[i].second < mi || ma < l[i].first)
                break;

            mi = max(mi, l[i].first);
            ma = min(ma, l[i].second);

            up[i] = ma - mi + 1;
        }

        //res = max(res, (ll)up[0]);
        for (int i = 0; i < n - 1; i++)
        {
            //cout << "# " << down[i] << " " << up[i] << endl;
            res = max(res, (ll)down[i] + (ll)up[i + 1]);
        }
    }

    {
        //R

        int up[112345];
        int down[112345];

        memset(up, 0, sizeof(up));
        memset(down, 0, sizeof(down));

        down[0] = r[0].second - r[0].first + 1;

        int mi = r[0].first;
        int ma = r[0].second;

        for (int i = 1; i < n; i++)
        {
            if (r[i].second < mi || ma < r[i].first)
                break;

            mi = r[i].first;
            ma = min(ma, r[i].second);

            down[i] = ma - mi + 1;
        }

        up[n - 1] = r[n - 1].second - r[n - 1].first + 1;

        mi = r[n - 1].first;
        ma = r[n - 1].second;

        for (int i = n - 2; i >= 0; i--)
        {
            if (r[i].second < mi || ma < r[i].first)
                break;

            mi = max(mi, r[i].first);
            ma = min(ma, r[i].second);

            up[i] = ma - mi + 1;
        }

        //res = max(res, (ll)up[0]);
        for (int i = 0; i < n - 1; i++)
        {
            //cout << "# " << down[i] << " " << up[i] << endl;
            res = max(res, (ll)down[i] + (ll)up[i + 1]);
        }
    }

    {
        //MAX

        int mai = -1;
        int ma = 0;

        REP(i, n)
        {
            if (l[i].second - l[i].first + 1 > ma)
            {
                ma = l[i].second - l[i].first + 1;
                mai = i;
            }
        }

        ll sum = ma;

        bool started = false;

        int le = -1;
        int ri = -1;

        REP(i, n)
        {
            if (i == mai)
                continue;

            if (!started)
            {
                le = l[i].first;
                ri = l[i].second;
                started = true;
            }
            else
            {
                if (l[i].second < le || ri < r[i].first)
                {
                    le = 0;
                    ri = -1;
                    break;
                }

                le = max(le, l[i].first);
                ri = min(ri, r[i].second);
            }
        }

        sum += max(0, ri - le + 1);

        res = max(res, sum);
    }

    {
        int le[112345];
        int ri[112345];

        int mi = l[0].first;
        int ma = l[0].second;

        REP(i, n)
        {
            if (l[i].second < mi || ma < l[i].first)
            {
                cout << res << endl;
                return 0;
            }

            le[i] = l[i].first;
            ri[i] = -r[i].first;
        }

        REP(i, n)
        {
            ll sum = l[i].second - l[i].first + 1;

            int mi = le[n - 1];
            if (l[i].first == mi)
                mi = le[n - 2];

            int ma = ri[n - 1];
            if (l[i].second == ma)
                ma = ri[n - 2];

            sum += ma - mi + 1;

            res = max(res, sum);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2944