#include <bits/stdc++.h>
using namespace std;
int n, k;
int t[500055];
int dp[2][65055];
int main() {
  scanf("%d %d", &k, &n);
  for (int i = 0; i < n; i++) scanf("%d", &t[i]);
  sort(t, t + n);
  vector<pair<int, int> > vec;
  for (int i = 0; i + 1 < n; i++) {
    vec.push_back(pair<int, int>(t[i + 1] - t[i], i));
  }
  sort(vec.begin(), vec.end());
  vector<int> vs;
  for (int i = 0; i < min(n - 1, k * 13); i++) {
    vs.push_back(vec[i].second);
    vs.push_back(vec[i].second + 1);
  }
  sort(vs.begin(), vs.end());
  vs.erase(unique(vs.begin(), vs.end()), vs.end());
  memset(dp[0], 63, sizeof(dp[0]));
  while (k--) {
    swap(dp[0], dp[1]);
    memset(dp[1], 63, sizeof(dp[1]));
    for (int i = 0; i + 1 < (int)vs.size(); i++) {
      int u = vs[i];
      dp[1][i + 2] = min(dp[1][i + 2], dp[0][i] + (t[vs[i + 1]] - t[u]));
    }
    for (int i = 1; i <= (int)vs.size(); i++)
      dp[1][i] = min(dp[1][i], dp[1][i - 1]);
  }
  printf("%d\n", dp[1][(int)vs.size()]);
  return 0;
}
