N,K = I() A = l() A.sort(reverse=True) ans = A[0] for i in range(1,K): if A[i] > 0: ans += A[i] else: break print(ans)