#include <bits/stdc++.h>
using namespace std;
int n, k;
int num[500005];
long long dp[500005];
int cnt[500005];
bool ok(int cost) {
  dp[0] = dp[1] = cnt[0] = cnt[1] = 0;
  for (int i = (2); i <= (n); i += (1)) {
    dp[i] = dp[i - 1];
    cnt[i] = cnt[i - 1];
    long long v = dp[i - 2] + num[i] - num[i - 1] - cost;
    int c = cnt[i - 2] + 1;
    if (v < dp[i] || v == dp[i] && c > cnt[i]) dp[i] = v, cnt[i] = c;
  }
  return (cnt[n] >= k);
}
int main() {
  scanf("%d %d", &k, &n);
  for (int i = (1); i <= (n); i += (1)) scanf("%d", &num[i]);
  sort(num + 1, num + n + 1);
  int l = 0, r = 1000000000;
  while (l <= r) {
    int m = (l + r) >> 1;
    if (ok(m))
      r = m - 1;
    else
      l = m + 1;
  }
  ok(l);
  printf("%lld\n", dp[n] + 1LL * l * k);
  return 0;
}
