n, k = map(int, input().split()) A = list(map(int, input().split())) A = sorted(A)[::-1] ans = 0 for i in range(k): if A[i] < 0: break ans += A[i] print(ans)