#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
int n, m, cnt;
int a[MAXN];
int dp[2][2][5005];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  memset(dp, 0x3f, sizeof dp);
  dp[0][0][0] = dp[1][0][0] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= i / 2; j++) {
      dp[cnt][0][j] = min(dp[cnt ^ 1][0][j], dp[cnt ^ 1][1][j]);
      dp[cnt][1][j] = dp[cnt ^ 1][0][j - 1] + a[i] - a[i - 1];
    }
    cnt ^= 1;
  }
  cout << min(dp[cnt ^ 1][0][m], dp[cnt ^ 1][1][m]) << endl;
  return 0;
}
