#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long long N = (long long)1e5 * 4;
const long long INF = (long long)1e18;
const double eps = (double)1e-6;
long long n, k, a[N], pos[N];
long long sum = 0;
vector<pair<long long, long long> > v;
signed main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (long long i = 2; i <= n; ++i) {
    v.push_back({a[i] - a[i - 1], i});
  }
  k--;
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (long long i = 0; i < (long long)(v.size()); ++i) {
    if (k != 0) {
      pos[v[i].second] = 1;
      k--;
    }
  }
  sum = a[n] - a[1];
  for (long long i = 1; i <= n; ++i) {
    if (pos[i] == 1) {
      sum -= a[i];
      sum += a[i - 1];
    }
  }
  cout << sum;
  return 0;
}
