#include <bits/stdc++.h>

struct Polje{
    int x;
    int y;
};

Polje a[300007];
int n, f, z;

using namespace std;
bool tmp (Polje a, Polje b) {
    if (a.x != a.y)
        return a.x < b.x;
    return a.y < b.y;
}
int main () {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> f>> z;
        a[i].x = f;
        a[i].y = z;
    }

    sort(a, a + n, tmp);
    
	int zb = 0;
    for (int i = 0; i < n; i++) {
        zb+=abs(a[i].x - i - 1) + abs(a[i].y - i - 1);
        //cout << zb << endl;
    }

    cout << zb << endl;
}