#include using namespace std; #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif #define int long long const int INF = 1LL << 60; signed main(){ int n, k; cin >> n >> k; vector a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } sort(a.begin(),a.end()); vector v; for(int i = 0; i < n-1; i++){ v.push_back(a[i+1] - a[i]); } sort(v.begin(),v.end()); int ans = 0; for(int i = 0; i < n-1 - (k-1); i++){ ans += v[i]; } cout << ans << endl; return 0; }