#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1000000000;
template <class T>
T read(T &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
  return x;
}
long long k, n;
long long a[500005];
long long dp[500005];
long long cnt[500005];
bool check(long long cost) {
  dp[0] = dp[1] = cnt[0] = cnt[1] = 0;
  for (long long i = 2; i <= n; ++i) {
    dp[i] = dp[i - 1], cnt[i] = cnt[i - 1];
    long long x = dp[i - 2] + a[i] - a[i - 1] - cost;
    if (x < dp[i] || (x == dp[i] && cnt[i - 2] + 1 > cnt[i]))
      dp[i] = x, cnt[i] = cnt[i - 2] + 1;
  }
  return cnt[n] >= k;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k >> n;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  long long l = 0, r = 2 * INF;
  long long ans = 2 * INF;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  check(ans);
  cout << dp[n] + ans * k << endl;
}
