#include <bits/stdc++.h>

using namespace std;

bool test = true;

struct zlatnik{
    int red;
    int kolona;
};

bool provera(zlatnik a, zlatnik b){
    if(a.red == b.red)
        test = false;
    return (a.red < b.red)?true:false;
}

int brPoteza(zlatnik a[], int n){
    sort(a, a + n, provera);
    if(test)
        return 0;
    int potezi = 0;
    for(int i = 0;i < n;i++){
        potezi += abs(a[i].red - (i + 1));
        potezi += abs(a[i].kolona - (i + 1));
    }
    return potezi;
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    zlatnik a[n];
    for(int i = 0;i < n;i++) cin >> a[i].red >> a[i].kolona;
    cout << brPoteza(a, n);
    return 0;
}