#include <bits/stdc++.h>
using namespace std;
long long n, k, a[500005], x[500005], dp[4][50005], m;
signed main() {
  cin >> m >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (long long i = 2; i <= n; i++) {
    x[i] = a[i] - a[i - 1];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long k = 1; k <= m; k++) {
      if (i / 2 >= k)
        dp[i % 3][k] = min(dp[(i - 1) % 3][k], dp[(i - 2) % 3][k - 1] + x[i]);
      else
        dp[i % 3][k] = 99999999;
    }
  }
  cout << dp[n % 3][m];
}
