#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const double eps = 1e-8;
int n, k, a[N], s[N];
double dp[N];
int Cal(double x) {
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    s[i] = s[i - 1];
    if (dp[i - 2] + a[i] - a[i - 1] + x < dp[i]) {
      dp[i] = dp[i - 2] + a[i] - a[i - 1] + x;
      s[i] = s[i - 2] + 1;
    }
  }
  return s[n];
}
int main() {
  while (~scanf("%d%d", &k, &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    double l = -1e9, r = 0, w;
    for (int i = 1; i <= 40; i++) {
      double mid = (l + r) * 0.5;
      if (Cal(mid) >= k)
        l = w = mid;
      else
        r = mid;
    }
    Cal(w);
    printf("%.0f\n", (dp[n] - w * k + eps));
  }
  return 0;
}
