#include using namespace std; int 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 ) break; ans += A[i]; } cout << ans << endl; }