#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795L;
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 1e17;
const long long N = 200500, M = 200500;
long long n = 1, m, k, w, h, x, y, i, j, sum, cur;
long long a, b, c, d, q;
long long ans = 0;
vector<long long> vans;
long long l = 0, r = 1e18;
string s;
bool f = 0, f1, f2;
int dd[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
long long v[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  cin >> n >> k;
  vector<long long> v(n);
  for (auto &e : v) cin >> e;
  multiset<long long> van;
  for (int i = 1; i < n; i++) {
    van.insert(v[i - 1] - v[i]);
  }
  ans = v[n - 1] - v[0];
  while (--k) {
    ans += *van.begin();
    van.erase(van.begin());
  }
  cout << ans << endl;
  return 0;
}
