#include <bits/stdc++.h>
using namespace std;
long long n, k, ans;
long long a[300005], c[300005];
pair<long long, long long> b[300005];
int con(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second > b.second) return 1;
  return 0;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = make_pair(i - 1, a[i] - a[i - 1]);
  }
  b[1] = make_pair(1, -1);
  sort(b + 1, b + n + 1, con);
  for (int i = 1; i < k; i++) {
    c[i] = b[i].first;
  }
  sort(c + 1, c + k);
  for (int i = 1; i < k; i++) {
    ans += a[c[i]];
    ans -= a[c[i] + 1];
  }
  ans -= a[1];
  ans += a[n];
  cout << ans;
}
