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