#include <bits/stdc++.h>
using namespace std;
int n, k, cnt, a, x, y, ans, minn = 0x3f3f3f3f;
priority_queue<int> q;
int main() {
  cin >> n >> k;
  k--;
  cin >> x;
  a = x;
  for (int i = 2; i <= n; i++) {
    cin >> y;
    int plus = y - x;
    if (cnt < k) {
      q.push(-plus);
      cnt++;
      minn = min(minn, -q.top());
    } else if (plus > minn) {
      q.pop();
      q.push(-plus);
      minn = -q.top();
    }
    x = y;
  }
  while (q.size()) ans -= q.top(), q.pop();
  cout << x - a - ans << endl;
  return 0;
}
