#include <bits/stdc++.h>
using namespace std;
int dp[10005][5005];
struct node {
  int len, x, y;
  bool operator<(const node& a) const { return len < a.x; }
};
int a[500005];
vector<node> vec;
map<int, int> vis;
int main() {
  int n, k;
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++) dp[i][j] = 1e9 + 1;
  dp[0][0] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= min(k, i / 2); j++) {
      dp[i][j + 1] = min(dp[i][j + 1], dp[i - 2][j] + a[i] - a[i - 1]);
      dp[i][j] = min(dp[i][j], dp[i - 1][j]);
    }
  }
  int mi = 1e9 + 1;
  for (int i = k; i <= n; i++) mi = min(mi, dp[i][k]);
  printf("%d\n", mi);
  return 0;
}
