#include <bits/stdc++.h>
using namespace std;
long long dp[3][5005];
long long k, n, t[500005];
int main() {
  scanf("%I64d%I64d", &k, &n);
  for (long long i = 1; i <= n; i++) scanf("%I64d", &t[i]);
  sort(t + 1, t + n + 1);
  for (long long i = 1; i < n; i++) t[i] = t[i + 1] - t[i];
  n--;
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j <= k; j++) dp[i][j] = 1000000000000000000;
  dp[0][0] = dp[1][0] = 0;
  dp[1][1] = t[1];
  for (long long i = 2; i <= n; i++) {
    long long last1 = (i - 1) % 3, last2 = (i - 2) % 3;
    for (long long j = 0; j <= k; j++) dp[i % 3][j] = 1000000000000000000;
    for (long long j = 0; j <= k; j++) {
      if (j == 0)
        dp[i % 3][j] = 0;
      else
        dp[i % 3][j] = min(dp[last1][j], dp[last2][j - 1] + t[i]);
    }
    if (i == n) printf("%I64d\n", dp[i % 3][k]);
  }
  return 0;
}
