#include <bits/stdc++.h>

using namespace std;

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


    int n ;

    cin >> n;

    int r[n],c[n];



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


        cin >> a >> b;

        r[i] = a-1;
        c[i] = b-1;

    }


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

    int sumaR = 0;
    int sumaC = 0;

    for(int i = 0 ; i < n ; i++)
    {
        sumaR += abs(i - r[i]);
        sumaC += abs(i - c[i]);

    }

    cout << sumaR + sumaC ;

    return 0;
}