N,K=map(int,input().split()) L=list(map(int,input().split())) s=0 for i in sorted(L)[::-1][:K]: if i > 0: s=s+i print(s)