#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{
    long N;
    scanf("%ld", &N);
    long* width = (long*) calloc(sizeof(long), N);
    long* height = (long*) calloc(sizeof(long), N);
    long x,y;
    long xMin = N, xMax = -1;
    long yMin = N, yMax = -1;
    for(long i = 0; i < N; i++)
    {
        scanf("%ld%ld",&x,&y);
        height[y - 1]++;
        width[x - 1]++;
        if(x - 1 > xMax)
        {
            xMax = x - 1;
        }
        if(x - 1 < xMin)
        {
            xMin = x - 1;
        }
        if(y - 1 < yMin)
        {
            yMin = y - 1;
        }
        if(y - 1 > yMax)
        {
            yMax = y - 1;
        }
    }

    long koraka = 0;

    for(long y = N - 1; y >= yMin; y--)
    {
        for(long pokusaj = (yMax > y) ? y : yMax; pokusaj >= yMin; pokusaj--)
        {
            if(height[pokusaj] >= 1)
            {
                koraka += abs(y - pokusaj);
                height[pokusaj]--;
                height[y]++;
                break;
            }
        }
    }
    for(long y = 0; y < yMin; y++)
    {
        for(long pokusaj = yMin; pokusaj <= yMax; pokusaj++)
        {
            if(height[pokusaj >= 1])
            {
                koraka += abs(pokusaj - y);
                height[pokusaj]--;
                height[y]++;
                break;
            }
        }
    }
    for(long x = N - 1; x >= xMin; x--)
    {
        for(long pokusaj = (xMax > x) ? x : xMax; pokusaj >= xMin; pokusaj--)
        {
            if(width[pokusaj] >= 1)
            {
                koraka += abs(x - pokusaj);
                width[pokusaj]--;
                width[x]++;
                break;
            }
        }
    }
    for(long x = 0; x < xMin; x++)
    {
        for(long pokusaj = xMin; pokusaj <= xMax; pokusaj++)
        {
            if(width[pokusaj >= 1])
            {
                koraka += abs(pokusaj - x);
                width[pokusaj]--;
                width[x]++;
                break;
            }
        }
    }
    printf("%ld",koraka);
}