#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, k;
  cin >> N >> k;
  vector<int> arr(N);
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    arr.push_back(a);
  }
  priority_queue<int> pq;
  for (int i = 0; i < N; i++) {
    pq.push(arr[i]);
    if (i >= k) pq.pop();
  }
  int res = 0;
  while (!pq.empty()) {
    res += pq.top();
    pq.pop();
  }
  cout << res;
  return 0;
}
