#include <bits/stdc++.h>
const int maxn = 3e5 + 7;
using namespace std;
int a[maxn], b[maxn];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; i++) b[i] = a[i + 1] - a[i];
  sort(b, b + n - 1);
  reverse(b, b + n - 1);
  int ans = a[n - 1] - a[0];
  for (int i = 0; i < min(n, m) - 1; i++) ans -= b[i];
  printf("%d\n", ans);
}
