#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> v;
vector<int> dif;
void read() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
}
bool cmp(int a, int b) { return a > b; }
void solve() {
  int sol = v[n - 1] - v[0];
  for (int i = 1; i < n; ++i) {
    dif.push_back(v[i] - v[i - 1]);
  }
  sort(dif.begin(), dif.end(), cmp);
  for (int i = 0; i < k - 1; ++i) sol -= dif[i];
  cout << sol;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(nullptr);
  read();
  solve();
  return 0;
}
