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