#include <bits/stdc++.h>
using namespace std;
float PHI = 1.6180339;
const float PI_F = 3.14159265358979f;
long long modpow(long long x, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long u = modpow(x, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * x) % m;
  return u;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cout << fixed << setprecision(12);
  long long n, k;
  cin >> n >> k;
  long long arr[n + 10];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<long long> v;
  for (long long i = 1; i < n; i++) {
    long long diff = arr[i - 1] - arr[i];
    v.push_back(diff);
  }
  sort(v.begin(), v.end());
  long long tot = arr[n - 1] - arr[0];
  for (long long i = 0; i < k - 1; i++) {
    tot += v[i];
  }
  cout << tot << "\n";
  return 0;
}
