#include #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; using namespace std; const int INF = 1e9; int main() { int N, K; cin >> N >> K; vector A(N); rep(i, N) cin >> A[i]; sort(A.rbegin(), A.rend()); ll ans = 0; rep(i, K) { if(A[i]>0) ans += A[i]; else break; } cout << ans << endl; return 0; }