#include <bits/stdc++.h>
using namespace std;
double eps = 1e-8;
const int N = 5e5 + 10;
int n, m;
int a[N], s[N];
double dp[N];
int check(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() {
  scanf("%d%d", &m, &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 <= 100; i++) {
    double mid = (l + r) * 0.5;
    if (check(mid) >= m) {
      l = w = mid;
    } else
      r = mid;
  }
  check(w);
  printf("%.0lf\n", dp[n] - w * m + eps);
  return 0;
}
