#include <iostream>
#include <set>
#include <algorithm>
#include <math.h>
#define NMAX 200000
using namespace std;

int N, suma1, suma2, br1, br2, svi1br, svi2br;
int r[NMAX], c[NMAX], niz1[NMAX], niz2[NMAX], svi1[NMAX], svi2[NMAX];

set<int> s1, s2;
set<int>::iterator it;
pair<set<int>::iterator, bool> par1, par2;

main(){	

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin >> N;
	
	for (int i=0; i<N; i++) {
		svi1[i] = i+1;
		svi2[i] = i+1; 
	}
	svi1br = N;
	svi2br = N;
		
		
	for(int i=0; i<N; i++) {
		cin >> r[i] >> c[i];
		par1 = s1.insert(r[i]);
		par2 = s2.insert(c[i]);
		if(par1.second == true) {
			remove(svi1, svi1+svi1br, r[i]);
			svi1br--; 
		}
		else niz1[br1++] = r[i];
		if (par2.second == true) {
			remove(svi2, svi2+svi2br, c[i]);
			svi2br--;
		}
		else niz2[br2++] = c[i];
	}
	
	sort(niz1, niz1+br1); sort(niz2, niz2+br2);
	
	for (int i=0; i<br1; i++)
		suma1 += abs(svi1[i]-niz1[i]);
	for (int i=0; i<br2; i++)
		suma2 += abs(svi2[i]-niz2[i]);
		
	cout << suma1+suma2;
	
}