#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int a[N + 5], b[N + 5];
int n, k;
pair<long long, int> DP(long long c) {
  long long yes = b[1] - c, no = 0;
  int yct = 1, nct = 0;
  for (int i = 2; i <= n; ++i) {
    long long xyes = no + b[i] - c, xno = min(no, yes);
    int xyct = nct + 1, xnct = (yes <= no ? yct : nct);
    yes = xyes, no = xno, yct = xyct, nct = xnct;
  }
  if (yes <= no)
    return make_pair(yes, yct);
  else
    return make_pair(no, nct);
}
long long Sol() {
  long long ans = -1;
  long long l = 0, r = (*max_element(b + 1, b + n + 1)) + 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();
  if (ans == -1)
    cout << DP(0).first << '\n';
  else
    cout << ans << '\n';
  return 0;
}
