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