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

namespace ConsoleApplication1
{
    class Program
    {
        static void funkcija(int n, int[] row, ref int zb)
        {
            int min = n + 1;
            int[] niz = new int[n];
            int br = 0;
            int k = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if ((Math.Abs(i - row[j]) < min))
                    {
                        min = Math.Abs(i - row[j]);
                        k=j;
                    }
                }
                row[k] = 56;
                k = 0;
                br++;
                zb += min;
                min = n + 1;
                
            }

        }
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            if (n == 1)
            {
                string[] fr = Console.ReadLine().Split();
                Console.WriteLine("0");
            }
            else if (n == 2)
            {
                string[] fr = Console.ReadLine().Split();
                string[] sc = Console.ReadLine().Split();
                if (fr[0] == sc[0] || fr[1] == sc[1])
                    Console.WriteLine("1");
                else
                    Console.WriteLine("0");
            }
            else
            {

                int[] col = new int[n];
                int[] row = new int[n];
                int br1 = 0;
                int br2 = 0;
                for (int i = 0; i < n; i++)
                {
                    string[] fr = Console.ReadLine().Split();
                    col[br1] = int.Parse(fr[0]);
                    br1++;
                    row[br2] = int.Parse(fr[1]);
                    br2++;
                }
                int min = 0;
                int minn = 0;
                funkcija(n, row, ref min);
                funkcija(n, col, ref minn);
                min += minn;
                Console.WriteLine(min);
            }
        }
    }
}