#include <bits/stdc++.h>
using namespace std;
int n, a[500021], k;
priority_queue<int, vector<int>, greater<int> > q;
int main() {
  scanf("%d%d", &n, &k);
  if (k >= n) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (i > 1) q.push(a[i - 1] - a[i]);
  }
  k--;
  int ans = a[n] - a[1];
  while (k--) {
    ans += q.top();
    q.pop();
  }
  printf("%d", ans);
  return 0;
}
