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