#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1);
const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2},  {1, 2},
                             {2, -1},  {2, 1},  {-1, -2}, {1, -2}};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const long long MOD = 1000000000 + 7;
vector<int> arr;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    arr.resize(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    vector<int> v;
    for (int i = 1; i < n; i++) {
      v.push_back(arr[i] - arr[i - 1]);
    }
    sort(v.rbegin(), v.rend());
    int ans = arr[n - 1] - arr[0];
    for (int i = 0; i < k - 1; i++) ans -= v[i];
    cout << ans << endl;
  }
}
