#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

struct zlatnik {
	int r, c;
};

bool porediRedove(zlatnik z1, zlatnik z2) {
	return (z1.r < z2.r);
}
bool porediKolone(zlatnik z1, zlatnik z2) {
	return (z1.c < z2.c);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	zlatnik zl[100];
	int N,brojPoteza=0;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> zl[i].r >> zl[i].c;
		zl[i].r--; zl[i].c--;
	}
	sort(zl, zl + N, porediRedove);
	for (int i = 0;i < N;i++) {
		if (zl[i].r != i) { 
			brojPoteza += abs(zl[i].r - i);
			zl[i].r = i;
		}
 	}
	sort(zl, zl + N, porediKolone);
	for (int i = 0;i < N;i++) {
		if (zl[i].c != i) {
			brojPoteza += abs(zl[i].c - i);
			zl[i].c = i;
		}
	}
	cout << brojPoteza << "\n";
}