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] elif L == 0: L += O[0] else: break print(L)