using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Point
    {
        public readonly int n;
        public readonly int x;
        public readonly int y;
        public bool visited = false;
        public Point(int n, int[] args)
        {
            this.n = n;
            x = args[0];
            y = args[1];
        }
        public static int Distance(Point a, Point b)
        {
            return Math.Min(Math.Abs(b.x - a.x), Math.Abs(b.y - a.y));
        }
    }

    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, Point[] points)
        {
            long[] mins = Enumerable.Repeat(long.MaxValue, N).ToArray();
            var dict = new Dictionary<Tuple<Point, Point>, int>();
            Array.Sort(points, (a, b) => a.x - b.x);
            for (int i = 1; i < N; ++i)
            {
                Point a = points[i - 1];
                Point b = points[i];
                int d = Math.Abs(b.x - a.x);
                mins[a.n] = Math.Min(d, mins[a.n]);
                mins[b.n] = Math.Min(d, mins[b.n]);
            }
            Array.Sort(points, (a, b) => a.y - b.y);
            for (int i = 1; i < N; ++i)
            {
                Point a = points[i - 1];
                Point b = points[i];
                int d = Math.Abs(b.y - a.y);
                mins[a.n] = Math.Min(d, mins[a.n]);
                mins[b.n] = Math.Min(d, mins[b.n]);
            }
            return mins.Sum() - mins.Min();
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            var points = new Point[N];
            for (int i = 0; i < N; ++i) { points[i] = new Point(i, ReadInts()); }
            Console.WriteLine(Solve(N, points));
        }
    }
}
