#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 0; i < n - k; i++) ans += max((long long)0, a[i]);
  long long sum = 0;
  for (long long i = n - k; i < n; i++) sum += a[i];
  ans += max((long long)0, sum);
  cout << ans << endl;
}
