#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10, inf = 1e18;
int n, k, t[N], cnt[N];
long long dp[N];
int ok(int x) {
  for (int i = 2; i <= n; i++) {
    cnt[i] = cnt[i - 1];
    dp[i] = dp[i - 1];
    if (t[i] - t[i - 1] <= x && cnt[i - 2] + 1 >= cnt[i]) {
      cnt[i] = cnt[i - 2] + 1;
      dp[i] = dp[i - 2] + t[i] - t[i - 1];
    }
  }
  return cnt[n];
}
int main() {
  scanf("%d %d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  sort(t + 1, t + 1 + n);
  int l = 0, r = t[n], mid, as;
  while (l <= r) {
    mid = (l + r) / 2;
    if (ok(mid) >= k) {
      as = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  ok(as);
  long long ans = dp[n];
  printf("%lld\n", ans - (cnt[n] - k) * as);
}
