#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, i, j, k, c, sek1,sek2;
    cin >> n;
    int a[n];
    int x[n];
    sek1 = 0;
    sek2 = 0;
    for(i = 0; i < n; i++)
    {
        cin >> a[i] >> x[i];
    }
    sort(a, a+n);
    //reverse(a, a+n);
    sort(x, x+n);
    //reverse(x, x+n);
        for(i = 0; i < n; i++)
    {
        sek1 = sek1 + abs(i-(a[i]-1));
        sek2 = sek2 + abs(i-(x[i]-1));

    }

    cout << sek1+ sek2;


    return 0;
}