using System;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Point[] points = new Point[n];
            int seconds = 0;
            for (int i = 0; i < n; i++)
            {
                string[] a = Console.ReadLine().Split(' ');
                points[i] = new Point(int.Parse(a[1]), int.Parse(a[0]));
            }
            sortY(points, n);
            for (int i = 0; i < n; i++)
            {
                seconds += Math.Abs(points[i].y - i - 1);
                points[i].y = i;
            }
            sortX(points, n);
            for (int i = 0; i < n; i++)
            {
                seconds += Math.Abs(points[i].x - i - 1);
                points[i].x = i;
            }
            Console.Write(seconds);
        }
        public class Point
        {
            public int x, y;
            public Point(int tempD1, int tempD2)
            {
                x = tempD1;
                y = tempD2;
            }
        }
        public static void sortY(Point[] points, int n)
        {
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    if (points[i].y > points[j].y)
                    {
                        int pom = points[i].y;
                        points[i].y = points[j].y;
                        points[j].y = pom;
                    }
                }
            }
        }
        public static void sortX(Point[] points, int n)
        {
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    if (points[i].x > points[j].x)
                    {
                        int pom = points[i].x;
                        points[i].x = points[j].x;
                        points[j].x = pom;
                    }
                }
            }
        }
    }
}