#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
int sign(double x) { return x < -EPS ? -1 : x > EPS; }
int dbcmp(double l, double r) { return sign(l - r); }
const int MAXN = 5e5 + 50;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch<'0' | ch> '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct Node {
  int val, pos;
  bool operator<(const Node &r) const { return val < r.val; }
} node[MAXN];
int t[MAXN], d[MAXN], vis[MAXN], a[10005], f[10005];
int dp[5005][2];
int main() {
  int k, n;
  scanf("%d%d", &k, &n);
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < n; i++) {
    scanf("%d", &t[i]);
  }
  sort(t, t + n);
  for (int i = 1; i < n; i++) {
    d[i] = t[i] - t[i - 1];
    node[i].val = d[i];
    node[i].pos = i;
  }
  sort(node + 1, node + n);
  for (int i = 1; i <= min(2 * k, n); i++) {
    vis[node[i].pos] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) {
      a[++cnt] = d[i];
      f[cnt] = (i != 1 && vis[i - 1]);
    }
  }
  dp[0][0] = 0;
  for (int i = 1; i <= cnt; i++) {
    for (int j = k; j >= 1; j--) {
      dp[j][0] = min(dp[j][1], dp[j][0]);
      if (f[i]) {
        dp[j][1] = dp[j - 1][0] + d[i];
      } else {
        dp[j][1] = min(dp[j - 1][0], dp[j - 1][1]) + d[i];
      }
    }
  }
  printf("%d\n", min(dp[k][0], dp[k][1]));
}
