#include<iostream>
#include<list>
#include<cmath>
using namespace std;

int N;
long long rez;
bool V[100000], K[10000];
int a, b, i, size;
list<int> l1, l2;
list<int>::iterator it;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	
	cin >> N;
	for (i = 0; i < N; i++){
		cin >> a >> b;
		if (!V[a]) V[a] = true;
		else l1.push_back(a);
		if (!K[b]) K[b] = true;
		else l2.push_back(b);
	}
	l1.sort();
	l2.sort();
	
//	for (it = l1.begin(); it != l1.end(); it++) cout << *it;
	
	for (i = 1, it = l1.begin(); it != l1.end(); i++) if (!V[i]){
		rez += abs(*it - i);
		it++;
		
	}
	for (i = 1, it = l2.begin(); it != l2.end(); i++) if (!K[i]){
		rez += abs(*it-i);
		it++;
	}
	cout << rez;
	return 0;
}