#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long ans = a[n - 1] - a[0];
  if (k == 1) {
    cout << ans;
    return 0;
  }
  multiset<int> s;
  for (int i = 1; i < n; ++i) {
    if (i < k) {
      s.insert(a[i] - a[i - 1]);
      continue;
    }
    if (a[i] - a[i - 1] <= *s.begin()) continue;
    s.erase(s.begin());
    s.insert(a[i] - a[i - 1]);
  }
  for (int i : s) ans -= i;
  cout << ans;
  return 0;
}
