#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5 + 5;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-10;
const long double PI = acos(-1.0);
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, n, m, sum = 0;
  cin >> n >> m;
  long long a[n + 1];
  a[0] = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  sum = a[n] * m;
  sort(a + 1, a + n);
  for (i = 1; i < m; i++) sum -= a[i];
  cout << sum;
  return 0;
}
