#include <bits/stdc++.h>
using namespace std;
int dp[10][5010];
int p;
int n, k, input[500005], a[500005];
bool flag[500005];
pair<int, int> m[500005];
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &input[i]);
  for (int i = 1; i < n; i++) {
    a[i] = input[i + 1] - input[i];
    m[i].first = a[i], m[i].second = i;
  }
  sort(m + 1, m + n);
  for (int i = 1; i <= min(n, 3 * k); i++) flag[m[i].second] = 1;
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < 4; i++) dp[i][0] = 0;
  p = 0;
  for (int i = 1; i <= n; i++) {
    if (!flag[i]) continue;
    p++;
    for (int j = 1; j <= min(p, k); j++) {
      dp[p % 4][j] =
          min(dp[(p - 1) % 4][j], dp[(p - 1 - flag[i - 1]) % 4][j - 1] + a[i]);
    }
  }
  printf("%d\n", dp[p % 4][k]);
  return 0;
}
