#include <bits/stdc++.h>
using namespace std;
pair<int, int> A[500010];
long long paixu(long long a[], long long low, long long high) {
  long long key = a[low];
  long long temp;
  while (low < high) {
    while ((low < high) && (a[high] >= key)) {
      high--;
    }
    if (a[high] < key) {
      a[low] = a[high];
      low++;
    }
    while ((low < high) && (a[low] <= key)) {
      low++;
    }
    if (a[low] > key) {
      a[high] = a[low];
      high--;
    }
  }
  a[low] = key;
  return low;
}
void quicksort(long long a[], long long start, long long end) {
  long long pos;
  if (start < end) {
    pos = paixu(a, start, end);
    quicksort(a, start, pos - 1);
    quicksort(a, pos + 1, end);
  }
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int t[500010];
int v[500010];
int dp[4][5010];
bool b[500010];
int main(int argc, char** argv) {
  int i;
  int n, out = 0, sub, k;
  int y, j;
  k = read();
  n = read();
  int p = 0;
  for (i = 1; i <= n; i++) {
    t[i] = read();
    ;
  }
  sort(t + 1, t + 1 + n);
  for (i = 1; i < n; i++) {
    v[i] = A[i].first = t[i + 1] - t[i];
    A[i].second = i;
  }
  sort(A + 1, A + n);
  for (int i = 1; i <= min(n, 3 * k); ++i) b[A[i].second] = 1;
  memset(dp, 100, sizeof(dp));
  for (int i = 0; i < 4; dp[i++][0] = 0)
    ;
  for (i = 1; i < n; ++i) {
    if (!b[i]) {
      continue;
    }
    p++;
    for (j = 1; j <= k; ++j) {
      dp[p & 3][j] =
          min(dp[(p - 1) & 3][j], dp[(p - 1 - b[i - 1]) & 3][j - 1] + v[i]);
    }
  }
  cout << dp[p & 3][k];
  return 0;
}
