n,k=[int(i) for i in input().split()] a=[int(i) for i in input().split()] a.sort(reverse=True) s=0 for i in range(k): if a[i]>0: s+=a[i] print(s)