#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, s = 0;
	cin >> n;
	int *r = new int[n];
	int *c = new int[n];
	for(int i = 0; i < n; i++) cin >> r[i] >> c[i];
	sort(r, r+n);
	sort(c, c+n);
	for(int i = 1; i <= n; i++) s += max(r[i-1] - i, i - r[i-1]) + max(c[i-1] - i, i - c[i-1]);
	cout << s;
}