#include using namespace std; int main() { int N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; i++) cin >> A.at(i); sort(A.rbegin(), A.rend()); int ans = 0; for (int i = 0, cnt = 0; i < N && cnt < K; i++) { if (A.at(i) < 0) continue; ans += A.at(i), cnt++; } cout << ans << "\n"; }