n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() c=0 for i in range(n): if a[~i]>0 and k>0: c+=a[~i] k-=1 print(c)