#include <bits/stdc++.h>
using namespace std;
int n, k;
int t[500055];
int dp[3][5055];
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 * 10); 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, 63, sizeof(dp));
  dp[1][0] = 0;
  dp[2][0] = 0;
  for (int i = 1; i < (int)vs.size(); i++) {
    swap(dp[0], dp[1]);
    swap(dp[1], dp[2]);
    for (int i = 0; i <= k; i++) {
      dp[2][i] = dp[1][i];
    }
    for (int j = 0; j < k; j++)
      dp[2][j + 1] = min(dp[2][j + 1], dp[0][j] + (t[vs[i]] - t[vs[i - 1]]));
  }
  printf("%d\n", dp[2][k]);
  return 0;
}
