#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
int k, n, t[MAXN];
vector<long long int> diff;
long long int pre[2][MAXN];
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", t + i);
  }
  sort(t + 1, t + 1 + n);
  for (int i = 2; i <= n; ++i) {
    diff.push_back(t[i] - t[i - 1]);
  }
  sort(diff.begin(), diff.end());
  diff.push_back((long long int)4e18);
  for (int i = 1; i <= n; ++i) {
    pre[i & 1][i] = diff[i - 1];
    if (i > 2) pre[i & 1][i] += pre[i & 1][i - 2];
  }
  long long int ans(9e18);
  ans = min(ans, pre[1][k * 2 - 1]);
  ans = min(ans, pre[0][k * 2]);
  printf("%lld\n", ans);
  return 0;
}
