import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E2 solver = new E2();
        solver.solve(1, in, out);
        out.close();
    }

    static class E2 {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int k = in.ni(), n = in.ni();
            int[] a = in.na(n);
            if (n > 1000) {
                ArrayUtils.randomShuffle(a);
            }
            Arrays.sort(a);
            Seg[] ss = new Seg[n - 1];
            for (int i = 0; i < n - 1; i++) {
                ss[i] = new Seg(a[i], a[i + 1]);
            }
            if (n > 1000) {
                ArrayUtils.randomShuffle(ss);
            }
            Arrays.sort(ss, Comparator.comparingInt((x) -> x.d));
            Arrays.sort(ss, 0, Math.min(3 * k, n - 1), Comparator.comparingInt((x) -> x.from));
            int[] b = new int[Math.min(6 * k, n)];
            Seg prev = ss[0];
            b[0] = prev.from;
            b[1] = prev.to;
            int bi = 2;
            for (int i = 1; i < Math.min(3 * k, n - 1); i++) {
                if (ss[i].from != prev.to) {
                    b[bi++] = ss[i].from;
                }
                b[bi++] = ss[i].to;
                prev = ss[i];
            }
            long[][][] dp = new long[bi][k + 1][2];
            for (int i = 0; i < bi; i++) {
                for (int j = 0; j < k + 1; j++) {
                    dp[i][j][0] = dp[i][j][1] = Long.MAX_VALUE;
                }
            }
            dp[0][0][0] = 0;
            long ans = Long.MAX_VALUE;
            for (int i = 1; i < bi; i++) {
                for (int kk = 0; kk < k; kk++) {
                    dp[i][kk][0] = Math.min(dp[i][kk][0], dp[i - 1][kk][1]);
                    if (dp[i - 1][kk][0] != Long.MAX_VALUE) {
                        dp[i][kk + 1][1] = Math.min(dp[i][kk + 1][1], dp[i - 1][kk][0] + a[i] - a[i - 1]);
                        dp[i][kk][0] = Math.min(dp[i][kk][0], dp[i - 1][kk][0]);
                    }
                }
                ans = Math.min(ans, dp[i][k][0]);
                ans = Math.min(ans, dp[i][k][1]);
            }
            out.println(ans);
        }

        class Seg {
            int from;
            int to;
            int d;

            public Seg(int from, int to) {
                this.from = from;
                this.to = to;
                d = to - from;
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public int[] na(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

    }

    static class ArrayUtils {
        public static void randomShuffle(Object[] a) {
            Random rand = new Random();
            int n = a.length;
            for (int i = 0; i < n; i++) {
                int x = rand.nextInt(n);
                int y = rand.nextInt(n - 1);
                if (y >= x)
                    y++;
                Object t = a[x];
                a[x] = a[y];
                a[y] = t;
            }
        }

        public static void randomShuffle(int[] a) {
            Random rand = new Random();
            int n = a.length;
            for (int i = 0; i < n; i++) {
                int x = rand.nextInt(n);
                int y = rand.nextInt(n - 1);
                if (y >= x)
                    y++;
                int t = a[x];
                a[x] = a[y];
                a[y] = t;
            }
        }

    }
}

