#include <iostream>
using namespace std;

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n, ukkoraka, tmp;
    cin >> n;
    int x[n];
    int y[n];
    ukkoraka = 0;
    for(int i = 0;i < n;i++){
        cin >> y[i] >> x[i];
    }

    int mx;
    int mpx = -1;
    int my;
    int mpy = -1;
    for(int i = 0;i < n;i++){//analiza po y i x osi
        mx = n+1;
        my = n+1;
        for(int j = 0;j < n;j++){//proveri svaki zlatnik da li je najblizi
            tmp = abs(y[j] - 1 - i);
            if(tmp < my && y[j] != -1){
                my = tmp;
                mpy = j;
            }
            tmp = abs(x[j] - 1 - i);
            if(tmp < mx && x[j] != -1){
                mx = tmp;
                mpx = j;
            }
        }
        ukkoraka += my + mx;
        y[mpy] = -1;
        x[mpx] = -1;
    }

    cout << ukkoraka;
}