#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
int n, m, cnt;
int a[MAXN];
int dp[2][2][5005];
pair<int, int> p[15005], q[MAXN];
bool vis[MAXN];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  memset(dp, 0x3f, sizeof dp);
  dp[0][0][0] = dp[1][0][0] = 0;
  if (m * 3 >= n) {
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j <= min(m, i / 2); j++) {
        dp[cnt][0][j] = min(dp[cnt ^ 1][0][j], dp[cnt ^ 1][1][j]);
        dp[cnt][1][j] = dp[cnt ^ 1][0][j - 1] + a[i] - a[i - 1];
      }
      cnt ^= 1;
    }
    printf("%d\n", min(dp[cnt ^ 1][0][m], dp[cnt ^ 1][1][m]));
  } else {
    for (int i = 1; i <= n - 1; i++) q[i] = make_pair(a[i] - a[i - 1], i);
    sort(q + 1, q + n);
    for (int i = 1; i <= 3 * m; i++) p[i] = make_pair(q[i].second, q[i].first);
    sort(p + 1, p + 3 * m + 1);
    for (int i = 1; i <= 3 * m; i++) {
      for (int j = 1; j <= min(m, (i + 1) / 2); j++) {
        dp[cnt][0][j] = min(dp[cnt ^ 1][0][j], dp[cnt ^ 1][1][j]);
        dp[cnt][1][j] = dp[cnt ^ 1][0][j - 1] + p[i].second;
        if (p[i].first != p[i - 1].first + 1)
          dp[cnt][1][j] =
              min(dp[cnt][1][j], dp[cnt ^ 1][1][j - 1] + p[i].second);
      }
      cnt ^= 1;
    }
    printf("%d\n", min(dp[cnt ^ 1][0][m], dp[cnt ^ 1][1][m]));
  }
  return 0;
}
