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


namespace debug
{
    class Program
    {
        static void Main(string[] args)
        {
            ProgramC a = new ProgramC();
            a.main();

        }
    }

    //ABC117
    class ProgramA
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = new int[3];
            for (int i = 0; i < 3; i++)
                num[i] = int.Parse(s[i]);

           Array.Sort(num);
           Console.WriteLine(num[2]*10 + num[1] + num[0]);
        }
    }

    class ProgramB
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);
            long x = long.Parse(s[2]);
            long y = long.Parse(s[3]);

            string[] xi = Console.ReadLine().Split(' ');
            string[] yi = Console.ReadLine().Split(' ');

            int[] a = new int[n];
            int[] b = new int[m];

            for (int i = 0; i < n; i++)
                a[i] = int.Parse(xi[i]);

            for (int i = 0; i < m; i++)
                b[i] = int.Parse(yi[i]);

            int max = a.Max();
            int min = b.Min();

            if(max < min)
            {
                if(min <= x || y <= max)
                    Console.WriteLine("War");
                else
                    Console.WriteLine("No War");
            }
            else
            {
                Console.WriteLine("War");
            }

        }
    }

    class ProgramC
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            string[] t = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);

            long[] a = new long[m];
            long[] dis = new long[m -1];

            for (int i = 0; i < m; i++)
                a[i] = long.Parse(t[i]);

            //ソートする
            Array.Sort(a);
            
            //座標距離感を入れる
            for (int i = 0;i < m - 1;i++)
                dis[i] = a[i + 1] - a[i];
            

            //ソートする
            Array.Sort(dis);

            long ans = 0;
            //小さい順にm-n番目までが最小移動
            for (int i = 0;i < m - n;i++)
            {
                ans += dis[i];
            }
            Console.WriteLine(ans);
        }
    }

    class ProgramD
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]); 
            long m = long.Parse(s[1]);
            long t = m;
            long count = 0;
            long[] fac = new long[n + 1];

            
            for(long i = 2;i <= Math.Sqrt(m);i++)
            {
                if(t % i == 0)
                {
                    while (t % i == 0)
                    {
                        t /= i;
                        fac[count]++;
                    }
                    count++;
                }

            }

            if(t != 1)
            {
                fac[count]++;
                count++;
            }

            long MOD = 1000000000 + 7;
            long sum = 1;

            //下準備
            nCk com = new nCk();
            com.fac = new long[n + 50];
            com.inv = new long[n + 50];
            com.finv = new long[n + 50];
            com.mod = MOD;
            com.max = n + 50;

            //メモ作成
            com.com_init();

            
            for (int i = 0;i < count;i++)
            {
                sum *= com.com(n + fac[i] - 1, fac[i]);
                sum %= MOD;
            }

            Console.WriteLine(sum);
        }

    }

    class nCk
    {
        public long mod;
        public long max;
        public long[] fac;
        public long[] inv;
        public long[] finv;


        //メモ作成(前準備)
        public void com_init()
        {
            fac[0] = 1;
            fac[1] = 1;
            finv[0] = 1;
            finv[1] = 1;
            inv[1] = 1;
            for (long i = 2; i < max; i++)
            {
                fac[i] = i * fac[i - 1] % mod;
                inv[i] = mod - inv[mod % i] * (mod / i) % mod;
                finv[i] = finv[i - 1] * inv[i] % mod;
            }
        }

        //二項計算
        public long com(long n, long k)
        {
            if (n < 0 || k < 0)
                return 0;
            if (n < k)
                return 0;
            return fac[n] * (finv[n - k] * finv[k] % mod) % mod;
        }

    }


}


Measured memory_bytes: 17888