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