#include <bits/stdc++.h>
using namespace std;
int a[505000], b[505000], n, k, dp[505000][2];
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  for (int i = 1; i < n; i++) b[i] = a[i] - a[i - 1];
  for (int i = 1; i <= k; i++) dp[i][0] = dp[i][1] = (int)2e9;
  for (int i = 1; i < n; i++) {
    for (int j = k; j >= 1; j--) {
      dp[j][0] = min(dp[j][0], dp[j][1]);
      dp[j][1] = min(dp[j][1], dp[j - 1][0] + b[i]);
    }
  }
  cout << min(dp[k][0], dp[k][1]) << endl;
  return 0;
}
