#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long fact[1000000];
void factorial() {
  fact[0] = fact[1] = 1;
  for (int i = 2; i < 1000000; i++)
    fact[i] = (i * (fact[i - 1]) % 1000000007 + 1000000007) % 1000000007;
}
signed main() {
  int T = 1;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    long long *arr = new long long[n];
    long long *aux = new long long[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long ans = arr[n - 1] - arr[0];
    for (int i = 0; i < n - 1; i++) aux[i] = arr[i] - arr[i + 1];
    sort(aux, aux + n - 1);
    for (int i = 0; i < k - 1; i++) ans += aux[i];
    cout << ans << '\n';
  }
}
