#include <bits/stdc++.h>
using namespace std;
const int INF = 1 * 1e9;
const long long limit = 2 * 1e12;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
const int MOD3 = 1e9 + 993;
const int maxn = 7e6 + 100;
int main() {
  cout.tie(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<long long> a(n + 1);
  vector<long long> p;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (i > 1) {
      p.push_back(a[i] - a[i - 1]);
    }
  }
  sort(p.begin(), p.end());
  if (k >= n) {
    cout << 0;
    return 0;
  }
  if (k == 1) {
    cout << a[n] - a[1];
    return 0;
  }
  long long ans = 0;
  for (int i = 0; i < n - k; ++i) {
    ans += p[i];
  }
  cout << ans;
  cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}
