#include <bits/stdc++.h>
using namespace std;
void kehsihba() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  kehsihba();
  long long n, k;
  cin >> n >> k;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (k == n) {
    cout << 0;
  } else if (k == 1) {
    cout << arr[n - 1] - arr[0];
  } else {
    long long ans = arr[n - 1] - arr[0];
    vector<long long> v;
    for (long long i = 1; i < n; i++) {
      v.push_back(arr[i - 1] - arr[i]);
    }
    sort(v.begin(), v.end());
    for (long long i = 0; i < k - 1; i++) {
      ans += v[i];
    }
    cout << ans;
  }
}
