#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[50010]; ll dist[10010]; cin >> N >> K; rep(i, N) cin >> a[i]; sort(a, a + N); for (int i = 0; i < N - 1; i++) dist[i] = a[i + 1] - a[i]; ll sum = 0LL; sort(dist, dist + N - 1); for (int i = 0; i < N - K; i++) sum += dist[i]; cout << sum << endl; return 0; }