#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int k, n, a[N], dp[2][N][2];
vector<pair<int, int>> temp, v;
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  for (int i = 0; i + 1 < n; i++) temp.push_back({a[i + 1] - a[i], i});
  sort(temp.begin(), temp.end());
  n = min((int)temp.size(), 3 * k);
  for (int i = 0; i < n; i++) v.push_back({temp[i].second, temp[i].first});
  sort(v.begin(), v.end());
  v.push_back({1e9, 0});
  for (int i = 0; i < 2; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; k < 2; k++) dp[i][j][k] = 1e9 + 9;
  for (int i = 0; i < n; i++) {
    int par = i & 1, to = !(i & 1);
    dp[par][0][0] = dp[par][0][1] = 0;
    bool can = abs(v[i].first - v[i + 1].first) > 1;
    for (int j = 0; j <= k; j++) {
      if (can)
        dp[to][j + 1][1] = min(dp[to][j + 1][1], dp[par][j][1] + v[i].second);
      dp[to][j][0] = min(dp[to][j][0], dp[par][j][0]);
      dp[to][j + 1][0] = min(dp[to][j + 1][0], dp[par][j][1] + v[i].second);
      dp[to][j][1] = min(dp[to][j][1], dp[par][j][0]);
    }
    for (int j = 0; j <= k; j++)
      for (int k = 0; k < 2; k++) dp[par][j][k] = 1e9 + 9;
  }
  printf("%d\n", min(dp[n & 1][k][0], dp[n & 1][k][1]));
}
