#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  if (n == k) {
    cout << 0;
    return;
  }
  long long int sum = 0;
  vector<int> diff;
  for (long long int i = 0; i < n - 1; i++) diff.push_back(a[i + 1] - a[i]);
  sort(diff.begin(), diff.end());
  for (long long int i = 0; i < n - k; i++) sum += diff[i];
  cout << sum;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TC = 1, t = 0;
  while (t++ < TC) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
