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

namespace Treci_Zadatak
{
    class Program
    {
        public static void Main()
        {
            int brojZlatnika = Convert.ToInt32(Console.ReadLine()), ispis = 0;
            int[] niz1 = new int[brojZlatnika];
            int[] niz2 = new int[brojZlatnika];
            for (int i = 0; i < brojZlatnika; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                niz1[i] = Convert.ToInt32(s[0]) - 1;
                niz2[i] = Convert.ToInt32(s[1]) - 1;
            }
            Array.Sort(niz1);
            Array.Sort(niz2);
            for (int i = 0; i < brojZlatnika; i++)
            {
                ispis += Math.Abs(i - niz1[i]);
                ispis += Math.Abs(i - niz2[i]);
            }
            Console.WriteLine(ispis);
        }
    }
}