#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using Graph = vector>; using ll = long long; typedef pair P_ll; typedef pair P; const ll INF_ll = 1e17; const int INF = 1e8; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template using min_priority_queue = priority_queue, greater>; int main() { ll N, K; cin >> N >> K; vector a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } sort(a.begin(), a.end()); ll ans = 0; vector b; for (int i = 1; i < N; i++) { ans += a[i] - a[i - 1]; b.push_back(a[i] - a[i - 1]); } sort(b.rbegin(), b.rend()); for (int i = 0; i < K - 1; i++) { ans -= b[i]; } cout << ans << endl; return 0; }