#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long powmod(long long a, long long b) {
  long long res = 1;
  if (a >= mod) a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    if (res >= mod) res %= mod;
    a = a * a;
    if (a >= mod) a %= mod;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  int a[n];
  long long diff[n + 1];
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    cin >> a[i];
  }
  diff[0] = a[0];
  for (long long i = (long long)(1); i < (long long)(n); i++) {
    diff[i] = a[i - 1] - a[i];
  }
  sort(diff + 1, diff + n + 1);
  long long ans = a[n - 1] - a[0];
  for (long long i = (long long)(1); i < (long long)(k); i++) {
    ans += diff[i];
  }
  cout << ans << '\n';
  return 0;
}
