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