#include <bits/stdc++.h>
using namespace std;
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);
  }
}
int x[500000];
int v[50000];
int main(int argc, char** argv) {
  int i;
  long long n, out = 0, sub, num;
  long long y, min;
  cin >> num;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (i = 1; i < n; i++) {
    sub = x[i] - x[i - 1];
    v[i - 1] = sub;
  }
  min = v[0];
  for (i = 0; i < num; i++) {
    for (i = 1; i < n - 1; i++) {
      if (min > v[i] && v[i] != 0) {
        min = v[i];
        y = i;
      }
    }
    out = out + min;
    v[y] = 0;
    v[y + 1] = 0;
    v[y - 1] = 0;
  }
  cout << out;
  return 0;
}
