#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
int dp[3][5005];
int a[N];
int n, m;
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, 125, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int s = i % 3;
    for (int j = 0; j <= m; j++) {
      dp[s][j] = min(dp[s][j], dp[(s - 1 + 3) % 3][j]);
      if (j > 0 && i > 1)
        dp[s][j] = min(dp[s][j], dp[(s - 2 + 3) % 3][j - 1] + a[i] - a[i - 1]);
    }
  }
  printf("%d\n", dp[n % 3][m]);
}
