n,k=map(int,input().split()) A=list(map(int,input().split())) A.sort() ans=A.pop() for i in range(-1,-k,-1): if A[i]<=0: break else: ans+=A[i] print(ans)