#include <bits/stdc++.h>
using namespace std;
int arr[(int)3e5 + 1];
int pref[(int)3e5 + 1];
void Solve() {
  long long n, ans, a, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 1; i < n; i++) pref[i] = arr[i] - arr[i - 1];
  sort(pref, pref + n);
  ans = 0;
  for (int i = 1; i <= n - k; i++) ans += pref[i];
  cout << ans << endl;
}
int main() { Solve(); }
