#include long long greedy(int n, int k, const std::vector &a) { std::vector aa = a; std::sort(aa.begin(), aa.end()); std::vector xa(n - 1); for (int i = 0; i + 1 < n; ++i) { xa[i] = aa[i + 1] - aa[i]; } std::sort(xa.begin(), xa.end(), std::greater()); long long res = aa.back() - aa.front(); for (int i = 0; i + 1 < k; ++i) { res -= xa[i]; } return res; } signed main() { std::ios::sync_with_stdio(false); int N, K; std::cin >> N >> K; std::vector A(N); for (int i = 0; i < N; ++i) { std::cin >> A[i]; } std::cout << greedy(N, K, A) << std::endl; return 0; }