#include <bits/stdc++.h>
using namespace std;
int k, n, dp[4][5002], tim[500002], tmp[500002];
bool vis[500002];
struct data {
  int val, id;
  friend bool operator<(data a, data b) { return a.val < b.val; }
} a[500002];
void read(int &x) {
  char ch = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int main() {
  read(k);
  read(n);
  for (int i = 1; i <= n; i++) read(tim[i]);
  sort(tim + 1, tim + n + 1);
  for (int i = 1; i < n; i++)
    tmp[i] = a[i].val = tim[i + 1] - tim[i], a[i].id = i;
  sort(a + 1, a + n);
  int tp = min(n, 3 * k);
  for (int i = 1; i <= tp; i++) vis[a[i].id] = 1;
  int tot = 0;
  memset(dp, 0x3f, sizeof dp);
  dp[0][1] = 0;
  for (int i = 1; i < n; i++) {
    if (!vis[i]) continue;
    tot++;
    for (int j = 1; j <= min(k, tot); j++)
      dp[tot & 3][j] = min(dp[(tot - 1) & 3][j],
                           dp[(tot - 1 - vis[i - 1]) & 3][j - 1] + tmp[i]);
  }
  printf("%d\n", dp[tot & 3][k]);
}
