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