#include #define rep(i,a,n) for (int i = a; i < n; i++) #define per(i,n,a) for (int i = n - 1; i >= a; i--) using namespace std; int main() { int n, k; cin >> n >> k; vector a(n); rep(i, 0, n) { cin >> a[i]; } sort(a.begin(), a.end()); vector sa(n - 1); rep(i, 0, n - 1) { sa[i] = a[i + 1] - a[i]; } sort(sa.begin(), sa.end()); long ans = 0; rep(i, 0, n - k) { ans += sa[i]; } cout << ans << endl; }