#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 1e5 + 7;
int a[maxn] = {0};
int d[maxn] = {0};
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; i++) d[i] = a[i + 1] - a[i];
  sort(d, d + n - 1);
  long long ans = a[n - 1] - a[0];
  int t = n - 2;
  while (--k) ans -= d[t--];
  printf("%lld\n", ans);
  return 0;
}
