#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

struct Seg {
    int l;
    int r;
    int id;
};
const int MAXN = 2e5;
bool used[MAXN];

template <bool T>
long long get_ans(auto v_left, auto v_right) {
    std::fill(used, used + MAXN, 0);
    long long ans = 0;
    int cur_x = 0;

    while (!v_right.empty() && !v_left.empty()) {
        if (T)
        {
            while (!v_left.empty() && used[v_left.back().id]) {
                v_left.pop_back();
            }
            if (!v_left.size()) {
                break;
            }
            if (!(cur_x >= v_left.back().l && cur_x <= v_left.back().r)) {
                int to_l = abs(cur_x - v_left.back().l);
                int to_r = abs(cur_x - v_left.back().r);
                if (to_l < to_r) {
                    ans += to_l;
                    cur_x = v_left.back().l;
                } else {
                    ans += to_r;
                    cur_x = v_left.back().r;
                }
            }
            used[v_left.back().id] = true;
            v_left.pop_back();

            while (!v_right.empty() && used[v_right.back().id]) {
                v_right.pop_back();
            }
            if (!v_right.size()) {
                break;
            }
            if (!(cur_x >= v_right.back().l && cur_x <= v_right.back().r)) {
                int to_l = abs(cur_x - v_right.back().l);
                int to_r = abs(cur_x - v_right.back().r);
                if (to_l < to_r) {
                    ans += to_l;
                    cur_x = v_right.back().l;
                } else {
                    ans += to_r;
                    cur_x = v_right.back().r;
                }
            }
            used[v_right.back().id] = true;
            v_right.pop_back();
        } else {
            while (!v_right.empty() && used[v_right.back().id]) {
                v_right.pop_back();
            }
            if (!v_right.size()) {
                break;
            }
            if (!(cur_x >= v_right.back().l && cur_x <= v_right.back().r)) {
                int to_l = abs(cur_x - v_right.back().l);
                int to_r = abs(cur_x - v_right.back().r);
                if (to_l < to_r) {
                    ans += to_l;
                    cur_x = v_right.back().l;
                } else {
                    ans += to_r;
                    cur_x = v_right.back().r;
                }
            }
            used[v_right.back().id] = true;
            v_right.pop_back();

            while (!v_left.empty() && used[v_left.back().id]) {
                v_left.pop_back();
            }
            if (!v_left.size()) {
                break;
            }
            if (!(cur_x >= v_left.back().l && cur_x <= v_left.back().r)) {
                int to_l = abs(cur_x - v_left.back().l);
                int to_r = abs(cur_x - v_left.back().r);
                if (to_l < to_r) {
                    ans += to_l;
                    cur_x = v_left.back().l;
                } else {
                    ans += to_r;
                    cur_x = v_left.back().r;
                }
            }
            used[v_left.back().id] = true;
            v_left.pop_back();
        }

    }
    return ans + abs(cur_x);
}

int main() {
    int n;
    ios_base::sync_with_stdio(0);
    cin >> n;
    std::vector<Seg> v_left(n);
    int cur = 0;
    for (auto& el : v_left) {
        cin >> el.l >> el.r;
        el.id = cur++;
    }
    auto v_right = v_left;

    sort(v_right.begin(), v_right.end(), [](const auto& lhs, const auto& rhs) {
        return lhs.l < rhs.l;
    });

    sort(v_left.begin(), v_left.end(), [](const auto& lhs, const auto& rhs) {
        return lhs.r < rhs.r;
    });
    reverse(v_left.begin(), v_left.end());

    std::cout << std::max(get_ans<true>(v_left, v_right), get_ans<false>(v_left, v_right));


}

Measured memory_bytes: 7552