#include <bits/stdc++.h>
using namespace std;
string char_to_str(char c) {
  string tem(1, c);
  return tem;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<long long> v;
  for (long long i = 1; i < n; ++i) {
    v.push_back(a[i - 1] - a[i]);
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  for (long long i = 0; i < k - 1; ++i) {
    ans -= v[i];
  }
  cout << a[n - 1] - a[0] - ans;
}
