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