#include using namespace std; using lint = long long; const lint MOD = 1e12; signed main(){ lint n, K; cin >> n >> K; vector a(n); for(int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); vector b; for(int i = 1; i < n; i++) b.push_back(a[i] - a[i - 1]); sort(b.begin(), b.end()); lint ans = 0; for(int i = 0; i < n - K; i++) ans += b[i]; cout << ans << endl; }