#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
const int INF = 1e9;
int K, N;
int t[maxn];
int diff[maxn];
int DP[2][5005][2];
int main() {
  scanf("%d %d", &K, &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &t[i]);
  sort(t + 1, t + 1 + N);
  for (int i = 1; i < N; ++i) {
    diff[i] = t[i + 1] - t[i];
  }
  int up = min(3 * K, N - 1);
  for (int i : {0, 1}) {
    for (int j = 0; j <= K; ++j) {
      for (int k : {0, 1}) {
        DP[i][j][k] = INF;
      }
    }
  }
  DP[0][0][0] = DP[0][0][1] = 0;
  for (int i = 1; i <= up; ++i) {
    for (int j = 1; j <= K; ++j) {
      int ci = i % 2;
      int pi = (i - 1) % 2;
      DP[ci][j][0] = min(DP[pi][j][0], DP[pi][j][1]);
      DP[ci][j][1] = min(DP[ci][j][1], DP[pi][j - 1][0] + diff[i]);
    }
  }
  printf("%d\n", min(DP[up % 2][K][0], DP[up % 2][K][1]));
}
