#include using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector As(N, 0LL); for (auto & a : As) cin >> a; sort(As.begin(), As.end()); long long total = As[N - 1] - As[0]; if (K == 1){ cout << total << endl; return 0; } vector Bs(N - 1, 0LL); for (int i = 0; i < N - 1; ++i) Bs[i] = As[i + 1] - As[i]; sort(Bs.begin(), Bs.end()); for (auto it = Bs.rbegin(); it != Bs.rbegin() + (K - 1); ++it){ total -= *it; } cout << total << endl; return 0; }