#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, i, k;
  cin >> n >> k;
  vector<long> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  vector<long> diff;
  for (i = 0; i < n - 1; i++) diff.push_back(v[i + 1] - v[i]);
  long minus = 0, diff_sum = v[n - 1] - v[0];
  sort(diff.begin(), diff.end(), greater<int>());
  for (i = 0; i < k - 1; i++) minus = minus + diff[i];
  cout << diff_sum - minus;
}
