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

namespace zlatinci
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] r = new int[200001];
            int[] c = new int[200001];
            int[] br = new int[2000001];


            int[] a = new int[2000001];



            int n = Convert.ToInt32(Console.ReadLine());

            string[] str;

            for (int i = 0; i < n; i++)
            {
                str = Console.ReadLine().Split();

                r[i] = Convert.ToInt32(str[0]);
                c[i] = Convert.ToInt32(str[1]) ;
                a[i] = i + 1;

            }

            int g = 0;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    br[j] = Math.Abs(a[i] - r[j]);

                    
                }
                g = g + min(br,n);
            }

           int        x = 0;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    br[j] = Math.Abs(a[i] - c[j]);

                    
                }
                x= x + min(br, n);
            }

            if ((x == 0 && g != 0)||(x!=0 && g==0))
            {
                Console.WriteLine(Convert.ToString(g));
            }
            else {
                if (x > g)
                {
                    Console.WriteLine(Convert.ToString(g));
                }
                else
                {
                    Console.WriteLine(Convert.ToString(x));
                }
            }


        }
        static int min(int[] a,int n)
        {
            int min = a[0];
            for (int i = 1; i < n; i++)
            {
                if (a[i] < min)
                {
                    min = a[i];
                }

            }
            return min;
        }
    }
}