#include <bits/stdc++.h>
using namespace std;
int a[500000], b[500000], c[500000];
bool cmp(int c, int d) { return a[c] < a[d]; }
int main() {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++) a[i] = a[i + 1] - a[i];
  for (int i = 0; i < n - 1; i++) b[i] = i;
  sort(b, b + n - 1, cmp);
  memset(c, 0, n * sizeof(int));
  int cnt = 0, ans = 0;
  for (int i = 0; i < n - 1 && cnt != k; i++) {
    if (!c[b[i]] && !c[b[i] + 1])
      ans += (a[b[i]]), c[b[i]] = c[b[i] + 1] = 1, cnt++;
  }
  cout << ans;
  return 0;
}
