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