#include <bits/stdc++.h>
using namespace std;
bool p[300005];
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  k--;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) v.push_back(make_pair(a[i] - a[i - 1], i));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < k; i++) {
    p[v[i].second] = 1;
  }
  int l = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] == 1) {
      ans += a[i - 1] - a[l];
      l = i;
    }
  }
  ans += a[n - 1] - a[l];
  cout << ans;
  return 0;
}
