#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
vector<int> sub;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    int temp;
    scanf("%d", &temp);
    arr.push_back(temp);
  }
  for (int i = 0; i < n - 1; i++) {
    sub.push_back(arr[i + 1] - arr[i]);
  }
  sort(sub.begin(), sub.end());
  long long int sum = 0;
  for (int i = 0; i < sub.size(); i++) sum += sub[i];
  for (int i = 0; i < k - 1; i++) {
    sum -= sub[sub.size() - 1 - i];
  }
  cout << sum;
  return 0;
}
