N, K = map(int, input().split(' ')) A = list(map(int, (input().split(' ')))) L = 0 O = sorted(A,reverse = True) for i in range(K): if 0 <= O[i]: L += O[i] else: break print(L)