#include #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,k,n) for(ll i=k;i<(ll)(n);i++) #define fore(i,a) for(auto &i:a) using namespace std; using ll = long long; int main() { int N,K; cin >> N >> K; vector A(N); rep(i,N) cin >> A[i]; sort(A.begin(),A.end(),greater()); int c = 0; rep(i,K) { if(A[i] < 0) break; c += A[i]; } cout << c << endl; }