Problem:
Score : 300 points

Problem Statement

We will play a one-player game using a number line and N pieces.

First, we place each of these pieces at some integer coordinate.

Here, multiple pieces can be placed at the same coordinate.

Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:

Move: Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.

Note that the coordinates where we initially place the pieces are already regarded as visited.

Find the minimum number of moves required to achieve the objective.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

-10^5 \leq X_i \leq 10^5

X_1, X_2, ..., X_M are all different.

Input

Input is given from Standard Input in the following format:

N M
X_1 X_2 ... X_M

Output

Find the minimum number of moves required to achieve the objective.

Sample Input 1

2 5
10 12 1 2 14

Sample Output 1

5

The objective can be achieved in five moves as follows, and this is the minimum number of moves required.

Initially, put the two pieces at coordinates 1 and 10.

Move the piece at coordinate 1 to 2.

Move the piece at coordinate 10 to 11.

Move the piece at coordinate 11 to 12.

Move the piece at coordinate 12 to 13.

Move the piece at coordinate 13 to 14.

Sample Input 2

3 7
-10 -3 0 9 -100 2 17

Sample Output 2

19

Sample Input 3

100 1
-100000

Sample Output 3

0

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

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 - 1; 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 + 1;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;
        }

    }


}