#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long n, a[300005], k;
vector<long long> dif;
long long sum = 0;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (i > 1) dif.push_back(a[i] - a[i - 1]);
  }
  sum = a[n] - a[1];
  sort(dif.begin(), dif.end());
  for (long long i = n - 2; i >= n - 2 - (k - 1) + 1; i--) sum -= dif[i];
  cout << sum;
}
