#include <bits/stdc++.h>
using namespace std;
int k, n;
int a[500010], b[500010];
bool cmp(int i, int j) { return a[i] < a[j]; }
vector<int> v;
int dp[4][5010];
int idx(int i) { return i % 3; }
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), b[i] = i;
  sort(a, a + n);
  for (int i = n - 1; i >= 1; i--) a[i] -= a[i - 1];
  sort(b + 1, b + n);
  int m = min(n - 1, 3 * k);
  v.clear();
  v.push_back(-3);
  for (int i = 1; i <= m; i++) v.push_back(b[i]);
  sort(v.begin(), v.end());
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 5010; j++) dp[i][j] = 1000000000;
  dp[0][0] = 0;
  dp[1][0] = 0;
  dp[2][0] = 0;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= k && j <= i; j++) {
      if (v[i] - v[i - 1] > 1)
        dp[idx(i)][j] = min(dp[idx(i - 1)][j], dp[idx(i - 1)][j - 1] + a[v[i]]);
      else if (i >= 2)
        dp[idx(i)][j] = min(dp[idx(i - 1)][j], dp[idx(i - 2)][j - 1] + a[v[i]]);
      else
        dp[idx(i)][j] = dp[idx(i - 1)][j];
    }
  printf("%d", dp[idx(m)][k]);
  return 0;
}
