#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
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], dp[2][M << 1];
pair<int, int> a[N];
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
void up(int &a, int 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 = min(m - 1, 2 * n + 10);
  sort(a, a + m);
  memset(dp, INF, sizeof(dp));
  for (int j = 0; j < m; j++) dp[0][j] = 0;
  dp[1][0] = a[0].second;
  for (int i = 1; i <= n; i++) {
    if (i > 1) dp[i & 1][0] = INF;
    for (int j = 1; j < m; j++) {
      dp[i & 1][j] = dp[i & 1][j - 1];
      if (a[j - 1].first + 1 != a[j].first) {
        up(dp[i & 1][j], dp[(i - 1) & 1][j - 1] + a[j].second);
      } else if (j > 1) {
        up(dp[i & 1][j], dp[(i - 1) & 1][j - 2] + a[j].second);
      }
    }
  }
  printf("%d\n", dp[n & 1][m - 1]);
  return 0;
}
