#include <bits/stdc++.h>
using namespace std;
const int N = 500010, K = 5010;
int n, arr[N], k, dp[2][4 * K];
int main() {
  vector<pair<int, int> > v;
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  sort(arr, arr + n);
  for (int i = 1; i < n; i++) {
    v.push_back(make_pair(arr[i] - arr[i - 1], i));
  }
  sort(v.begin(), v.end());
  vector<pair<int, int> > v2;
  for (int i = 0; i < min((int)v.size(), k * 4); i++) {
    v2.push_back(make_pair(v[i].second, v[i].first));
  }
  sort(v2.begin(), v2.end());
  for (int i = k - 1; i >= 0; i--) {
    for (int j = v2.size() - 1; j >= 0; j--) {
      if (i == k - 1) {
        dp[(i & 1)][j] =
            min((j < v2.size() - 1 ? dp[(i & 1)][j + 1] : 1000000000),
                v2[j].second);
      } else {
        dp[(i & 1)][j] = 1000000000;
        if (j + 1 < (int)v2.size()) dp[(i & 1)][j] = dp[(i & 1)][j + 1];
        if (j + 1 < (int)v2.size() && abs(v2[j + 1].first - v2[j].first) > 1)
          dp[(i & 1)][j] =
              min(dp[(i & 1)][j], v2[j].second + dp[(i & 1) ^ 1][j + 1]);
        if (j + 2 < (int)v2.size()) {
          dp[(i & 1)][j] =
              min(dp[(i & 1)][j], v2[j].second + dp[(i & 1) ^ 1][j + 2]);
        }
      }
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}
