n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 0 while k: if a[-1] < 0: break ans += a.pop() k -= 1 print(ans)