import java.util.*;

public class Main
{
    public static void main(String[] args) 
    {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt(), N = scanner.nextInt();
        int[] time = new int[N];
        for (int i = 0; i < N; i++)
            time[i] = scanner.nextInt();
        Arrays.sort(time);
        Interval[] interval = new Interval[N - 1];
        for (int i = 0; i < N - 1; i++)
            interval[i] = new Interval(time[i], time[i + 1]);
        Arrays.sort(interval);
        int count = 0, res = 0, prev = -1;
        ArrayList<Integer> ar = new ArrayList<Integer>();
        
        for (int i = 0; i < N - 1 && count < K; i++)
        {
            if (!ar.contains(interval[i].start) && !ar.contains(interval[i].end))
            {
                //System.out.println(interval[i].start + " " + interval[i].end);
                res += interval[i].end - interval[i].start;
                prev = interval[i].end;
                ar.add(interval[i].start);
                ar.add(interval[i].end);
                count++;
            }
        }
        System.out.println("" + res);
        /*Interval[] interval = new Interval[N / 2];
        for (int i = 0; i < N / 2; i++)
            interval[i] = new Interval(time[2 * i], time[2 * i + 1]);
        int res = 2000000000;
        Arrays.sort(interval);
        for (int i = 0; i < interval.length; i++)
            System.out.println(interval[i].start + " " + interval[i].end);
        System.out.println();
        if (interval.length >= K)
        {
            int temp = 0;
            for (int i = 0; i < K; i++)
                temp += interval[i].end - interval[i].start;
            res = Math.min(res, temp);
        }
        
        if (N % 2 == 0)
            interval = new Interval[N / 2 - 1];
        else
            interval = new Interval[N / 2];
        for (int i = 0; i < interval.length; i++)
            interval[i] = new Interval(time[2 * i + 1], time[2 * i + 2]);
        Arrays.sort(interval);
        for (int i = 0; i < interval.length; i++)
            System.out.println(interval[i].start + " " + interval[i].end);
        if (interval.length >= K)
        {
            int temp = 0;
            for (int i = 0; i < K; i++)
                temp += interval[i].end - interval[i].start;
            res = Math.min(res, temp);
        }
        
        System.out.println("" + res);*/
    }
}

class Interval implements Comparable
{
    public int start, end;
    
    public Interval(int a, int b)
    {
        start = a;
        end = b;
    }
    
    public int compareTo(Object b)
    {
        Interval p = (Interval)b;
        if ((end - start) - (p.end - p.start) == 0)
        {
            if (end != p.end)
                return end - p.end;
            else
                return start - p.start;
        }
        return (end - start) - (p.end - p.start);
        /*if (end != p.end)
            return end - p.end;
        return start - p.start;*/
    }
}