#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vii = vector<pii>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
clock_t startTime;
double getCurrentTime() {
  return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int N = 100100;
ll mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  startTime = clock();
  int n, k;
  cin >> n >> k;
  vi a(n);
  vii diff;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
  }
  for (int i = 0; i < (n - 1); i++) {
    diff.emplace_back(a[i + 1] - a[i], i);
  }
  sort(diff.rbegin(), diff.rend());
  vector<bool> mark(n, false);
  for (int i = 0; i < k - 1; i++) {
    mark[diff[i].second] = 1;
  }
  int cost = 0;
  int last = a[0];
  mark[n - 1] = true;
  for (int i = 0; i < (n); i++) {
    if (mark[i]) {
      cost += a[i] - last;
      if (i != n - 1) last = a[i + 1];
    }
  }
  cout << cost << "\n";
  return 0;
}
