#include <bits/stdc++.h>
using namespace std;
int a[500001], dp[3][5001];
int main() {
  int k, n;
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  for (int i = n - 1; i > 0; i--) a[i] = a[i] - a[i - 1];
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < 3; i++) dp[i][0] = 0;
  dp[1][1] = a[1];
  for (int i = 2; i < n; i++) {
    for (int j = 1; j <= (i + 1) / 2 && j <= k; j++) {
      dp[i % 3][j] = min(dp[(i - 1) % 3][j], dp[(i - 2) % 3][j - 1] + a[i]);
    }
  }
  printf("%d", dp[(n - 1) % 3][k]);
  return 0;
}
