#include <bits/stdc++.h>   using namespace std;   long long n, k, a[300005], b[300005];   int main() {     cin >> n >> k;     k--;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];     long long res = a[n] - a[1];     sort(b + 1, b + n);     for (int i = n - 1; i >= n - k; i--) res -= b[i];     cout << res;     return 0;   }   