N,K=map(int,input().split()) A=list(map(int,input().split())) A.sort(reverse=True) X=0 for i in range(K): if A[i]<0 and i>=1: break X+=A[i] print(X)