#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (long long &a : A) cin >> a;
  vector<long long> diff;
  for (int i = 1; i < N; i++) {
    diff.push_back(A[i - 1] - A[i]);
  }
  sort(diff.begin(), diff.end());
  long long ans = A[N - 1] - A[0];
  for (int i = 1; i < K; i++) ans += diff[i - 1];
  cout << ans;
  return 0;
}
