#include <bits/stdc++.h>
using namespace std;
int t[500005], g[500005], dp[3][250005];
int main() {
  int k, n;
  scanf("%d%d", &k, &n);
  dp[0][0] = dp[1][0] = dp[2][0] = 0;
  for (int i = 1; i <= k; i++) dp[0][i] = dp[1][i] = dp[2][i] = 1e9;
  for (int i = 0; i < n; i++) scanf("%d", &t[i]);
  sort(t, t + n);
  for (int i = 1; i < n; i++) g[i] = t[i] - t[i - 1];
  for (int i = 1; i < n; i++) {
    int beg = i / 2 - 2;
    if (beg < 0) beg = 0;
    for (int j = beg; j <= i / 2 + 2 && j <= k; j++) {
      dp[2][j] = min(dp[1][j], dp[0][j - 1] + g[i]);
    }
    for (int j = beg; j <= i / 2 + 2 && j <= k; j++) {
      dp[0][j] = dp[1][j];
      dp[1][j] = dp[2][j];
    }
  }
  printf("%d\n", dp[2][k]);
  return 0;
}
