#include <bits/stdc++.h>
using namespace std;
int64_t max(int32_t a, int64_t b) { return max((int64_t)a, b); }
bool used[3 * 100000 + 500];
vector<int64_t> g[3 * 100000 + 500];
int64_t a[3 * 100000 + 500];
pair<int64_t, int64_t> dfs(int64_t v) {
  used[v] = true;
  pair<int64_t, int64_t> mn = {a[v], a[v]};
  for (int64_t x : g[v]) {
    if (!used[x]) {
      pair<int64_t, int64_t> f = dfs(x);
      mn.first = min(mn.first, f.first);
      mn.second = max(mn.second, f.second);
    }
  }
  return mn;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int64_t n, k;
  cin >> n >> k;
  vector<pair<int64_t, pair<int64_t, int64_t>>> dst;
  for (int64_t i = 0; i < n; i++) cin >> a[i];
  for (int64_t i = 0; i < n - 1; i++) {
    dst.push_back({a[i + 1] - a[i], {i, i + 1}});
  }
  sort(dst.begin(), dst.end());
  int64_t cur_k = n;
  int64_t cur = 0;
  while (cur_k > k) {
    g[dst[cur].second.first].push_back(dst[cur].second.second);
    g[dst[cur].second.second].push_back(dst[cur].second.first);
    cur++;
    cur_k--;
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < n; i++) {
    if (!used[i]) {
      pair<int64_t, int64_t> x = dfs(i);
      ans += (x.second - x.first);
    }
  }
  cout << ans;
}
