#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B;
  vector<int> vec(A);
  for (int i = 0; i < A; i++) {
    cin >> vec.at(i);
    sort(vec.begin(), vec.end());
  }
  if (A >= 3) {
    for (int i = A - B; i < A; i++) {
      C += vec.at(i);
    }
    cout << C << endl;
  } else if (A == 2) {
    if (B == 1) {
      cout << vec.at(A - 1);
    } else {
      cout << vec.at(A - 1) + vec.at(A - 2) << endl;
    }
  } else {
    cout << vec.at(A - 1) << endl;
  }
}
