#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 9;
int a[maxn], b[maxn];
bool cmp(int a, int b) { return a > b; }
int main() {
  int i, j, k, n;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i < n; i++) {
    b[i] = a[i + 1] - a[i];
  }
  sort(b + 1, b + n, cmp);
  int ans = a[n] - a[1];
  int cnt = 0;
  for (i = k - 1; i > 0; i--) {
    ans -= b[++cnt];
  }
  cout << ans << endl;
}
