#include #include #include #include #include #include #include #include #include #include #include const int MOD = 1e9 + 7; const int iINF = 100000000; #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long int; using P = pair; using edge = struct { int to; int cost; }; int main() { int N, K; ll a[10010]; ll dist[10010]; cin >> N >> K; rep(i, N) cin >> a[i]; sort(a, a + N); for (int i = 1; i < N; i++) dist[i - 1] = a[i] - a[i - 1]; ll sum = 0LL; sort(dist, dist + N - 1); for (int i = 0; i < N - K; i++) sum += dist[i]; cout << sum << endl; return 0; }