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