#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
	int N, *x,*y,moves = 0,*duplicates,*holes;
	int i,j,counter_holes = 0, counter_duplicates = 0,x_offset = 0, y_offset = 0;

	std::cin >> N;

	x = new int[N];
	y = new int[N];
	duplicates = new int[N];
	holes = new int[N];

	for (i = 0; i < N; i++) {
		std::cin >> x[i];
		std::cin >> y[i];
	}

	std::sort(x, x + N);
	std::sort(y, y + N);

	for (i = 1; i < N; i++) {
		if (x[i - 1] != i - x_offset && x[i-1]) {
			holes[counter_holes] = i - x_offset;
			counter_holes++;
		}
		//else {
			if (x[i - 1] == x[i]) {
				duplicates[counter_duplicates] = x[i];
				counter_duplicates++;
				x_offset++;
			}

		if (y[i - 1] != i - y_offset && y[i - 1]){
			holes[counter_holes] = i - y_offset;
			counter_holes++;
		}
			if (y[i - 1] == y[i] ) {
				duplicates[counter_duplicates] = y[i];
				counter_duplicates++;
				y_offset++;
			}

	}

	if (x[i - 1] != i - x_offset && x[i - 1]){
		holes[counter_holes] = i - x_offset;
		counter_holes++;
	}

	if (y[i - 1] != i - y_offset && y[i - 1] ){
		holes[counter_holes] = i - y_offset;
		counter_holes++;
	}
	for (i = 0; i < counter_duplicates; i++) {
		moves += std::abs(duplicates[i] - holes[i]);
	}

    std::cout << moves; 
}