#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, in, f = 0;
  vector<int> a, c;
  vector<pair<int, int> > b;
  cin >> n >> k;
  cin >> in;
  a.push_back(in);
  for (int i = 1; i != n; i++) {
    cin >> in;
    a.push_back(in);
    b.push_back({in - a[i - 1], i - 1});
    f++;
  }
  sort(b.begin(), b.end());
  for (int i = 1; i != k; i++) {
    c.push_back(b[f - i].second);
  }
  sort(c.begin(), c.end());
  int p = 0, ans = 0;
  for (int i = 0; i != c.size(); i++) {
    ans += a[c[i]] - a[p];
    p = c[i] + 1;
  }
  cout << ans + a[a.size() - 1] - a[p];
  return 0;
}
