#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  int n, k, answer = 0;
  cin >> n >> k;
  vector<int> a(n);
  vector<pair<int, int>> diff(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0) {
      diff[i - 1].first = a[i] - a[i - 1];
      diff[i - 1].second = i - 1;
    }
  }
  sort(diff.begin(), diff.end());
  vector<int> cord;
  for (int i = 0; i < k - 1; i++) {
    cord.push_back(diff.back().second);
    diff.pop_back();
  }
  sort(cord.begin(), cord.end());
  int nax = 0;
  for (auto x : cord) {
    answer += a[x] - a[nax];
    nax = x + 1;
  }
  answer += a[n - 1] - a[nax];
  cout << answer << '\n';
  return 0;
}
