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