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