#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i;
  cin >> n >> k;
  int arr[n];
  for (i = 0; i < n; ++i) cin >> arr[i];
  int dif[n - 1];
  for (i = 0; i < n - 1; ++i) {
    dif[i] = arr[i + 1] - arr[i];
  }
  sort(dif, dif + n - 1);
  long long int sum = 0;
  for (i = 1; i <= k - 1; ++i) {
    sum += dif[n - 1 - i];
  }
  long long cost = arr[n - 1] - arr[0] - sum;
  cout << cost;
  return 0;
}
