n,k=map(int,input().split()) ans=[] n=list(map(int,input().split())) n.sort(reverse=True) for i in range(k): if n[i]>=0: ans.append(n[i]) print(sum(ans))