#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int L[500005], R[500005];
long long a[500005], t[500005];
pair<long long, long long> tree[1000005];
int n, k;
void upd(int i, long long z) {
  int now = n + i + 1;
  tree[now] = make_pair(z, i);
  now >>= 1;
  while (now) {
    tree[now] = min(tree[now * 2], tree[now * 2 + 1]);
    now >>= 1;
  }
}
void init() {
  for (int i = 1; i <= n + 1; i++) {
    L[i] = i - 1;
    R[i] = i + 1;
  }
  L[1] = -1;
  R[n + 1] = -1;
}
void del(int x) {
  int l = L[x], r = R[x];
  if (r != -1) L[r] = l;
  if (l != -1) R[l] = r;
}
int main() {
  fill(tree, tree + 1000005, make_pair(9876543219876543, 9876543219876543));
  scanf("%d%d", &k, &n);
  for (int(i) = (1); (i) <= (n); (i) += (1)) scanf("%lld", t + i);
  for (int(i) = (2); (i) <= (n); (i) += (1)) a[i] = t[i] - t[i - 1];
  a[1] = 9876543219876543, a[n + 1] = 9876543219876543;
  init();
  for (int(i) = (1); (i) <= (n + 1); (i) += (1)) upd(i, a[i]);
  long long ans = 0;
  while (k--) {
    pair<long long, long long> p = tree[1];
    ans += p.first;
    int t = p.second;
    p.first = a[L[t]] + a[R[t]] - p.first;
    a[t] = p.first;
    upd(L[t], 9876543219876543);
    upd(R[t], 9876543219876543);
    del(L[t]);
    del(R[t]);
    upd(t, a[t]);
  }
  printf("%lld", ans);
}
