#include <bits/stdc++.h>
using namespace std;
int expo(int base, int exponent, int mod) {
  int ans = 1;
  while (exponent != 0) {
    if ((exponent & 1) == 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}
struct M {
  int a;
  int b;
};
int inf = 10000000000;
M sto[500005];
M sto2[500005];
int k, n;
bool cmp(M a, M b) { return (a.b - a.a) < (b.b - a.a); }
bool cmp2(M a, M b) { return a.a < b.a; }
int dp[2 * 5005][5005];
int cnt = 0;
int solve(int i, int c) {
  if (c == k) return 0;
  if (i >= cnt) return inf;
  if (dp[i][c] == -1) {
    if ((i + 1 < cnt) && sto2[i].b == sto2[i + 1].a) {
      int x, y;
      x = solve(i + 2, c + 1) + sto2[i].b - sto2[i].a;
      if ((i + 2 < cnt) && (sto2[i + 1].b == sto2[i + 2].a)) {
        y = solve(i + 3, c + 1) + sto2[i + 1].b - sto2[i + 1].a;
      } else {
        y = solve(i + 2, c + 1) + sto2[i + 1].b - sto2[i + 1].a;
      }
      dp[i][c] = min(x, y);
    } else {
      dp[i][c] = sto2[i].b - sto2[i].a + solve(i + 1, c + 1);
    }
  }
  return dp[i][c];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> k >> n;
  int ary[n];
  for (int i = 0; i < n; ++i) {
    cin >> ary[i];
  }
  sort(ary, ary + n);
  for (int i = 0; i < n - 1; ++i) {
    sto[i].a = ary[i];
    sto[i].b = ary[i + 1];
  }
  sort(sto, sto + n - 1, cmp);
  for (int i = 0; i < 2 * k + 1; ++i) {
    if (i >= n - 1) break;
    sto2[i] = sto[i];
    cnt++;
  }
  sort(sto2, sto2 + cnt, cmp2);
  for (int i = 0; i < cnt + 1; ++i) {
    for (int j = 0; j < k + 1; ++j) dp[i][j] = -1;
  }
  cout << solve(0, 0) << endl;
  return 0;
}
