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