#include "bits/stdc++.h" using namespace std; int main() { long long N, K; cin >> N >> K; vectorA(N); for (long long i = 0; i < N; i++) cin >> A.at(i); sort(A.begin(), A.end(), greater()); long long ans = 0; for (long long i = 0; i < K; i++) ans = max(ans, ans + A.at(i)); cout << ans << endl; }