N, K = map(int, input().split()) List = list(map(int,input().split())) value = 0 List.sort(reverse = True) if max(List) < 0: value = max(List) for i in range(K): if List[i] > 0: value += int(List[i]) print(value)