#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
const long long N = 1e5 + 8;
const long long INF = 1e18;
int prime[N] = {0};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  multiset<long long> s;
  long long a[n + 1], res = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (i >= 2) {
      res += a[i] - a[i - 1];
      s.insert(a[i] - a[i - 1]);
    }
  }
  long long rem = k - 1;
  while (rem--) {
    long long it = *(s.rbegin());
    res -= it;
    s.erase(--s.end());
  }
  cout << res << endl;
}
