#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
int main() {
  long long n, k;
  cin >> n >> k;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  vector<long long> diff;
  for (long long i = 0; i < n - 1; i++) diff.push_back(arr[i] - arr[i + 1]);
  sort(diff.begin(), diff.end());
  long long ans = arr[n - 1] - arr[0];
  for (long long i = 0; i < k - 1; i++) ans += diff[i];
  cout << ans << endl;
  return 0;
}
