#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef struct
{
	long long int xp, yp, xv, yv;
	
}Polje;

int main()
{
    unsigned long long int N;
    bool lo, provera = true;
	vector<Polje> v;
	unsigned long long int x, y, pot = 0;
	cin >> N;
    Polje o;
    o.xv = -1;
    o.xp = -1;
    o.yv = -1;
    o.yp = -1;
    bool niz[N][N];
    for(unsigned long long int i = 0; i < N; i++)
	{
		for(unsigned long long int p = 0; p < N; p++)
	    {
            niz[i][p] = false;
	    }
	}

	for(unsigned long long int i = 0; i < N; i++)
	{
		cin >> y >> x;
		niz[x][y] = true;
	}
	for(unsigned long long int i = 0; i < N; i++)
    {
        if(niz[i][0] == true)
        {
            for(unsigned long long int p = 1; p < N; p++)
            {
                if(niz[i][p] != true)
                {
                    provera = false;
                }
            }
            if(provera)
            {
                for(unsigned long long int p = 0; p < N; p++)
                {
                    pot = pot + abs(i - p);
                }
            }
        }
    }
    for(unsigned long long int i = 0; i < N; i++)
    {
        lo = false;
        for(unsigned long long int p = 0; p < N; p++)
        {
            if(niz[i][p] == true)
            {
                if(lo == true)
                {
                    o.xv = i;
                    o.yv = p;
                }
                else
                {
                    lo = true;
                }
            }
        }
        if(lo == false)
        {
            o.xp = i;
            for(unsigned long long int p = 0; p < N; p++)
            {
                if(niz[p][i] == false)
                {
                    o.yp = p;
                    goto Kraj;
                }
            }
        }
        Kraj:
        if(o.xv != -1 && o.xp != -1 && o.yp != -1 && o.yv != -1)
        {
            v.push_back(o);
            o.xv = -1;
            o.xp = -1;
            o.yv = -1;
            o.yp = -1;
        }
    }

	for(unsigned long long int i = 0; i < v.size(); i++)
	{
		pot = pot + abs(v[i].xv - v[i].yv) + abs(v[i].xp - v[i].yp);
	}
	cout << pot << endl;
	
	return 0;
}