N, K = map(int, input().split()) l = list(map(int, input().split())) l.sort() l.reverse() # print(l) ans = 0 for i in range(K): if l[i] <= 0: break ans += l[i] print(ans)