#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int a[N + 5], b[N + 5];
int n, k;
long long dp[N + 5][3], cnt[N + 5][3];
pair<long long, int> DP(long long c) {
  long long sum = 0, num = 0;
  for (int i = 1; i <= n; i++) b[i] -= c;
  for (int i = 1; i <= n; i++) {
    if (dp[i - 1][0] < dp[i - 1][1]) {
      dp[i][0] = dp[i - 1][0];
      cnt[i][0] = cnt[i - 1][0];
    } else {
      dp[i][0] = dp[i - 1][1];
      cnt[i][0] = cnt[i - 1][1];
    }
    dp[i][1] = dp[i - 1][0] + b[i];
    cnt[i][1] = cnt[i - 1][0] + 1;
  }
  if (dp[n][0] < dp[n][1]) {
    sum = dp[n][0];
    num = cnt[n][0];
  } else {
    sum = dp[n][1];
    num = cnt[n][1];
  }
  for (int i = 1; i <= n; i++) b[i] += c;
  return make_pair(sum, num);
}
long long Sol() {
  long long ans = -1;
  long long l = 0, r = (1e9) + 10, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    pair<long long, int> F = DP(mid);
    if (F.second >= k) {
      ans = F.first + (long long)k * mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ans;
}
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i < n; ++i) b[i] = a[i + 1] - a[i];
  --n;
  auto ans = Sol();
  cout << ans << '\n';
  return 0;
}
