#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void read(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void write(T &&...args) {
  ((cout << args << " "), ...);
  cout << endl;
}
int main(int argc, char **argv) {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n, 0);
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr.begin(), arr.end());
  int mini = 0;
  for (int i = 0; i < k; i++) {
    mini = accumulate(arr.begin(), arr.end() - k + 1, 0);
  }
  cout << mini << endl;
  return 0;
}
