N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) res = 0 for i in range(K): if A[i] > 0 or i == 0: res += A[i] else: break print(res)