#include #include #include #include #include #include #include #include using ll = long long; using namespace std; ll a[5010]; vector v; int main(void) { int N, K; cin >> N >> K; for (int i = 0; i < N; ++i) cin >> a[i]; sort(a, a + N); for (int i = 1; i < N; ++i) { v.push_back(a[i] - a[i - 1]); } ll ans = 0; sort(v.begin(), v.end()); for (int i = 0; i < N - K; ++i) ans += v[i]; cout << ans << endl; return 0; }