#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 998244353;
int n, k;
int a[maxn];
int divt[maxn];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  vector<int> pos(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    divt[i] = a[i + 2] - a[i + 1];
    pos[i] = i;
  }
  sort(pos.begin(), pos.end(), [](int x, int y) { return divt[x] > divt[y]; });
  long long res = 0;
  for (int i = k - 1; i < n - 1; ++i) {
    res += divt[pos[i]];
  }
  printf("%lld\n", res);
  return 0;
}
