#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n), tp;
  vector<pair<int, int>> p(n - 1);
  for (auto &e : a) cin >> e;
  sort(a.begin(), a.end());
  for (int i = 0; i + 1 < n; i++) p[i] = {a[i + 1] - a[i], i};
  sort(p.begin(), p.end());
  int ts = min(n - 1, 3 * k + 100);
  for (int i = 0; i < ts; i++) tp.push_back(p[i].second);
  sort(tp.begin(), tp.end());
  int dp[ts][k + 1][2];
  memset(dp, -1, 4 * 2 * (k + 1) * ts);
  dp[0][k][0] = 0;
  dp[0][k - 1][1] = a[tp[0] + 1] - a[tp[0]];
  for (int i = 1; i < ts; i++)
    for (int j = k; j >= 0; j--) {
      if (dp[i - 1][j][0] == -1 && dp[i - 1][j][1] == -1)
        ;
      else if (dp[i - 1][j][0] == -1)
        dp[i][j][0] = dp[i - 1][j][1];
      else if (dp[i - 1][j][1] == -1)
        dp[i][j][0] = dp[i - 1][j][0];
      else
        dp[i][j][0] = min(dp[i - 1][j][0], dp[i - 1][j][1]);
      if (j < k && dp[i - 1][j + 1][0] != -1)
        dp[i][j][1] = dp[i - 1][j + 1][0] + a[tp[i] + 1] - a[tp[i]];
      if (j < k && dp[i - 1][j + 1][1] != -1 && tp[i - 1] + 1 != tp[i])
        dp[i][j][1] =
            min(dp[i - 1][j + 1][1] + a[tp[i] + 1] - a[tp[i]], dp[i][j][1]);
    }
  if (dp[ts - 1][0][0] < 0) dp[ts - 1][0][0] = 1e9;
  if (dp[ts - 1][0][1] < 0) dp[ts - 1][0][1] = 1e9;
  cout << min(dp[ts - 1][0][0], dp[ts - 1][0][1]);
  cin >> n;
}
