#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[300005];
struct nobe {
  int sum, pos;
  bool operator<(const nobe& g) const { return sum < g.sum; }
} b[300005];
bool visit[300005];
int main() {
  int k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i], visit[i] = 0;
  for (int i = 2; i <= n; ++i) {
    b[i - 1].sum = a[i] - a[i - 1];
    b[i - 1].pos = i - 1;
  }
  sort(b + 1, b + 1 + n - 1);
  for (int i = n - 1; i >= n - k + 1; --i) {
    visit[b[i].pos] = 1;
  }
  long long ans = 0;
  int last = 1;
  for (int i = 1; i < n; ++i) {
    if (visit[i]) {
      ans += (a[i] - a[last]);
      last = i + 1;
    }
  }
  ans += (a[n] - a[last]);
  cout << ans << endl;
  return 0;
}
