N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) A = A[:K] print(sum([a for a in A if a > 0]))