#include <bits/stdc++.h>

using namespace std;

int x[200010], y[200010];

int main()
{
	int n;
	
	cin >> n;
	
	for(int i = 0; i < n; i++)
	{
		int r, c;
		
		cin >> r >> c;
		
		x[r]++;
		y[c]++;
	}
	
	int s = 0, p = 0;
	
	for(int i = 1; i <= n; i++)
	{
		s += abs(p);
		
		p += x[i] - 1;
	}
	for(int i = 1; i <= n; i++)
	{
		s += abs(p);
		
		p += y[i] - 1;
	}
	
	
	cout << s;
	return 0;
}