#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main() {
    int n;
    cin >> n;

    vector<int> levaStrana;
    vector<int> desnaStrana;

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;

        levaStrana.push_back(a);
        desnaStrana.push_back(b);
    }

    sort(levaStrana.begin(), levaStrana.end(), greater<int>());
    sort(desnaStrana.begin(), desnaStrana.end(), greater<int>());

    int output = 0;
    for (int i = 0; i < n; i++) {
        int dodatak = n - i;
        int ostatak = abs(levaStrana[i] - dodatak);
        output+=ostatak;
        ostatak = abs(desnaStrana[i] - dodatak);
        output+=ostatak;
    }

    cout << output;

    return 0;
}