N, K = [int(i) for i in input().strip().split(' ')] print(sum(sorted([int(i) for i in input().strip().split(' ') if int(i) > 0], reverse=True)[:K]))