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