#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(0); int N, K; cin >> N >> K; vector a(N); rep(i, N) cin >> a[i]; sort(a.begin(), a.end()); vector d(N - 1); rep(i, N - 1) d[i] = a[i + 1] - a[i]; sort(d.begin(), d.end()); ll ans = 0; rep(i, N - K) ans += d[i]; cout << ans << endl; }