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