N, K = map(int, input().split()) A_list = list(map(int, input().split())) A_list.sort(reverse=True) if A_list[0] < 0: print(A_list[0]) else: print(sum([a for a in A_list[:K] if a > 0]))