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