#include <bits/stdc++.h>
using namespace std;
int main() {
  priority_queue<int> p;
  int a, b;
  cin >> a >> b;
  int arr[a];
  for (int i = 0; i < a; i++) cin >> arr[i];
  for (int i = 0; i < a; i++) {
    if (p.size() > b) p.pop();
    p.push(arr[i]);
  }
  int count = 0;
  while (p.size() > 0) {
    count += p.top();
    p.pop();
  }
  cout << count;
  return 0;
}
