#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 100;
const long long inf = 1e18 + 100;
double EPS = 1e-12;
const int INF = 2000000000;
template <class T>
inline void cinn(T &ret) {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  ret = c - '0';
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
}
inline void coutt(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) {
    coutt(a / 10);
  }
  putchar(a % 10 + '0');
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, k;
  cinn(k);
  cinn(n);
  long long arr[n];
  for (int i = 0; i < n; i++) cinn(arr[i]);
  sort(arr, arr + n);
  vector<int> vec(n - 1);
  for (int i = 0; i < n - 1; i++) vec[i] = arr[i + 1] - arr[i];
  long long dp[3][5005];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j <= 5000; j++) dp[i][j] = INF;
  dp[0][0] = 0;
  for (int i = 1; i < 3; i++) dp[i][0] = 0;
  dp[0][1] = vec[0];
  int sz = vec.size();
  for (int i = 1; i < sz; i++) {
    for (int j = max(1, min(i, k - 1000)); j <= k; j++) {
      int t = i % 3;
      dp[t][j] = INF;
      dp[t][j] = min(dp[t][j], dp[(i - 1 + 3) % 3][j]);
      dp[t][j] = min(dp[t][j], dp[(i - 2 + 3) % 3][j - 1] + vec[i]);
    }
  }
  coutt(dp[(vec.size() - 1) % 3][k]);
  return 0;
}
