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