#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int a[N], b[N];
bool cmp(int a, int b) { return a > b; }
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i > 1) {
      b[i] = a[i] - a[i - 1];
      sum += b[i];
    }
  }
  sort(b + 2, b + n + 1, cmp);
  for (int i = 2; i <= k; i++) {
    sum -= b[i];
  }
  cout << sum << endl;
  return 0;
}
