#include #define int long long #define double long double using namespace std; const int MOD = 1000000007; const int INF = 1e14; using Graph = vector>; signed main(){ int N, K; cin >> N >> K; vector A(N); for( int i = 0; i < N; i++ ) cin >> A[i]; sort(A.rbegin(), A.rend()); int ans = 0; for( int i = 0; i < K; i++ ){ if( A[i] < 0 ) continue; ans += A[i]; } cout << ans << endl; }