#include #define rep(i, ss, ee) for (int i = ss; i < ee; ++i) using namespace std; void solve() { int N, K, sum = 0; cin >> N >> K; vector v(N); rep(i, 0, N) { cin >> v[i]; } sort(v.begin(), v.end(), greater{}); rep(i, 0, K) if (v[i] > 0) sum += v[i]; cout << sum << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); getchar(); }