#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int k, n;
int a[N];
int dp[2][5005][2];
int diff[N];
int main() {
  scanf("%d %d", &k, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++) diff[i] = a[i + 1] - a[i];
  memset(dp, 0x3f, sizeof dp);
  dp[0][k - 1][1] = diff[0];
  dp[0][k][0] = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = min(n - 1 - i, k); j >= max(0, k - i); j--) {
      dp[i & 1][j][0] = min(dp[!(i & 1)][j][0], dp[!(i & 1)][j][1]);
      dp[i & 1][j][1] = dp[!(i & 1)][j + 1][0] + diff[i];
    }
  }
  cout << min(dp[(n - 2) & 1][0][0], dp[(n - 2) & 1][0][1]);
}
