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

namespace ConsoleApp30
{
    class Program
    {
        private static void zameni(int[,] a, int p, int d,int j)
        {
            int v;

            v = a[p,j];
            a[p,j] = a[d,j];
            a[d,j] = v;
        }
        private static void qs(int[,] a, int l, int d ,int j)
        {
            /*   for (int i = 0; i < 4; i++)
               { Console.Write(a[i] + " ");


               }
               Console.WriteLine();*/
            if (d - l == 1)
            {
                if (a[l,j] > a[d,j])
                {
                    zameni(a, l, d,j);
                }
            }
            else
            {
                int x = a[(l + d) / 2,j];
                int i = l;
                int c = d;
                do
                {
                    while (a[i,j] < x)
                    {
                        i++;
                    }
                    while (a[c,j] > x)
                    {
                        c--;
                    }
                    if (i <= c)
                    {
                        zameni(a, i, c,j);
                        i++;
                        c--;
                    }
                }
                while (i <= c);
                if (c > l)
                {
                    qs(a, l, c,j);
                }
                if (i < d)
                {
                    qs(a, i, d,j);
                }
            }
        }
        static void Main(string[] args)
        {
            int n, res = 0;
            n = int.Parse(Console.ReadLine());
            int[,] a = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                string[] r = Console.ReadLine().Split();
                for (int j = 0; j < 2; j++)
                {
                    a[i, j] = int.Parse(r[j]);
                }
            }
            qs(a, 0, n - 1, 0);
            qs(a, 0, n - 1, 1);
            for (int i = 0; i < n; i++)
            {
                //Console.WriteLine(" "+a[i,0]+" "+i+" "+Math.Abs(i-a[i,0]));    
                res =res+Math.Abs(i+1 - a[i, 0]) + Math.Abs(i+1 - a[i, 1]);
            }

          /*  for(int i = 0; i < n; i++)
            {
                Console.WriteLine();
                for (int j = 0; j < 2; j++)
                    Console.Write(a[i,j]+" ");
            }*/
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}