using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Petlja_C__Zlatnici
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] str;
            int[] Xniz = new int[n+1];
            int[] Yniz = new int[n+1];

            for(int i=1;i<=n;i++)
            {
                str = Console.ReadLine().Split(' ');
                Xniz[i] = Convert.ToInt32(str[0]);
                Yniz[i] = Convert.ToInt32(str[1]);
            }

            int[] Ximanema = new int[n+1];
            int koraci = 0;
            int[] Yimanema = new int[n+1];

            for(int i=1;i<=n;i++)
            {

                if(Ximanema[Xniz[i]]==0)                
                {
                    Ximanema[Xniz[i]] = 1;
                }

                if (Yimanema[Yniz[i]] == 0)
                {
                    Yimanema[Yniz[i]] = 1;
                }
            }

            for (int i = 1; i <= n; i++)
            {
                if (Ximanema[Xniz[i]] == 1)
                {
                    Ximanema[Xniz[i]] = 2;
                }

                else if (Ximanema[Xniz[i]] == 2)
                {
                    bool nadjen = false;
                    int j = 1;

                    while (!nadjen && j <= n)
                    {
                        if (Ximanema[j] == 0)
                        {
                            koraci += Math.Abs(j - Xniz[i]);
                            Xniz[i] = j;
                            Ximanema[j] = 1;
                            nadjen = true;
                        }
                        j++;
                    }
                }

                if (Yimanema[Yniz[i]] == 1)
                {
                    Yimanema[Yniz[i]] = 2;
                }

                else if (Yimanema[Yniz[i]] == 2)
                {
                    bool nadjen = false;
                    int j = 1;

                    while (!nadjen && j <= n)
                    {
                        if (Yimanema[j] == 0)
                        {
                            koraci += Math.Abs(j - Yniz[i]);
                            Yniz[i] = j;
                            Yimanema[j] = 1;
                            nadjen = true;
                        }
                        j++;
                    }
                }
            }

            Console.WriteLine(koraci);
            Console.ReadLine();
        }
    }
}