#include<iostream>
#include<math.h>
int niz1[200001], niz2[200001];
int main()
{
	int n, uk = 0;
	std::cin >> n;
	for (int i = 1; i <= n; i++)
		std::cin >> niz1[i] >> niz2[i];
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			if (niz1[i] > niz1[j]) {
				std::swap(niz1[i], niz1[j]);
				std::swap(niz2[i], niz2[j]);
			}

	for (int i = 1; i <= n; i++)
	{
		uk += abs(i - niz1[i]);
	}
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			if (niz2[i] > niz2[j]) {
				std::swap(niz1[i], niz1[j]);
				std::swap(niz2[i], niz2[j]);
			}
	for (int i = 1; i <= n; i++)
	{
		uk += abs(i - niz2[i]);
	}
	std::cout << uk;
	//system("pause");
	//return 0;
}