#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double PI = acos(-1.0);
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 9;
int dcmp(double x) { return (x > eps) - (x < -eps); }
const int N = 5e5 + 10, M = 5e3 + 10;
int b[N];
long long dp[3][M];
pair<int, int> a[N];
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
void up(long long &a, long long b) {
  if (a > b) a = b;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }
  sort(b, b + m);
  for (int i = 0; i < m; i++) {
    if (i) a[i - 1] = {i, b[i] - b[i - 1]};
  }
  sort(a, a + m - 1, cmp);
  m = 2 * n - 1;
  sort(a, a + m);
  memset(dp, INF, sizeof(dp));
  dp[0][0] = 0, dp[0][1] = a[0].second;
  for (int i = 1; i < m; i++) {
    int k = (i + 2) % 3, now = i % 3;
    for (int j = 0; j <= n; j++) {
      dp[now][j] = dp[k][j];
    }
    if (i < 2) continue;
    if (a[k].first + 1 == a[i].first) k = (k + 2) % 3;
    for (int j = 1; j <= n; j++) {
      up(dp[now][j], dp[k][j - 1] + 1LL * a[i].second);
    }
  }
  printf("%lld\n", dp[(m + 2) % 3][n]);
  return 0;
}
