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

namespace _1feladat
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> X = new List<string>();
            List<string> Y = new List<string>();

            string a = Console.ReadLine();
            int length = Convert.ToInt32(a);
            for (int i = 0; i !=length; i++)
            {
                string b = Console.ReadLine();
                string[] b2 = b.Split(' ');
                X.Add(b2[0]);
                Y.Add(b2[1]);
            }

            X.Sort();
            Y.Sort();

            int lepes = 0;
            for(int i = 1; i != length+1; i++)
            {
                if (X[i - 1] != i.ToString())
                {
                    lepes += Math.Abs(i - Convert.ToInt32(X[i - 1]));
                }

                if (Y[i - 1] != i.ToString())
                {
                    lepes += Math.Abs(i - Convert.ToInt32(Y[i - 1]));
                }
            }
            Console.WriteLine(lepes);

        }
    }
}