#include <bits/stdc++.h>
using namespace std;
long long n, k, a[500005], dp[5005][5005];
int32_t main() {
  ios::sync_with_stdio(false);
  cin >> k >> n;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (long long i = 0; i <= k; ++i)
    for (long long j = 0; j <= n; ++j) dp[i][j] = 1e18;
  for (long long i = 1; i < n; ++i) {
    dp[1][i] = a[i + 1] - a[i];
    dp[1][i] = min(dp[1][i], dp[1][i - 1]);
  }
  for (long long i = 2; i <= k; ++i) {
    dp[i][i + i - 1] = dp[i - 1][i + i - 3] + a[i + i] - a[i + i - 1];
    for (long long j = i + i; j < n; ++j) {
      dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 2] + a[j + 1] - a[j]);
    }
  }
  cout << dp[k][n - 1] << endl;
  return 0;
}
