#include <bits/stdc++.h>
using namespace std;
const int N = 255001;
const long double PI = acos(-1);
int n, k, a[N << 1];
vector<pair<int, int> > v;
int dp[10010][5050];
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second < b.second) return 1;
  if (a.second > b.second) return 0;
  return (a.first < b.first);
}
int calc(int idx, int t) {
  if (idx >= v.size()) return (t == k) ? 0 : 1000000000;
  if (t > k) return 100000000;
  int& ret = dp[idx][t];
  if (ret != -1) return ret;
  ret = calc(idx + 1, t);
  ret = min(
      ret, v[idx].first +
               calc(idx + 1 + (v[idx].second + 1 == v[idx + 1].second), t + 1));
  return ret;
}
signed main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  for (int i = 1; i < n; i++) v.push_back(make_pair(a[i] - a[i - 1], i));
  sort(v.begin(), v.end());
  while (v.size() >= 10010) v.pop_back();
  sort(v.begin(), v.end(), comp);
  memset(dp, -1, sizeof dp);
  cout << calc(0, 0);
}
