#include <bits/stdc++.h>
using namespace std;
int n, k;
int sums[300001];
int ans;
int a, b;
int main() {
  cin >> n >> k;
  if (n == k) {
    cout << "0";
    return 0;
  }
  int x, y;
  cin >> x;
  a = x;
  for (int i = 2; i <= n; i++, x = y) {
    cin >> y;
    sums[i - 1] = y - x;
    if (i == n) b = y;
  }
  sort(sums + 1, sums + n);
  ans = b - a;
  for (int i = n - 1; i >= n - k + 1; i--) ans -= sums[i];
  cout << ans;
  return 0;
}
