#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  vector<long long> b(n - 1);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (i) {
      b[i - 1] = a[i - 1] - a[i];
    }
  }
  sort(b.begin(), b.end());
  long long ans = a[n - 1] - a[0];
  long long p = 0;
  long long t = min(k - 1, n - 1);
  for (long long i = 0; i < t; i++) {
    p += b[i];
  }
  cout << max<long long>(ans + p, 0);
  return 0;
}
