#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> vc(n), dif;
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    cin >> vc[i];
    if (i > 0) {
      dif.push_back(vc[i] - vc[i - 1]);
      res += dif[i - 1];
    }
  }
  sort(dif.begin(), dif.end());
  for (long long i = 0; i < k - 1; i++) {
    res -= dif[n - 2 - i];
  }
  cout << res;
}
