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