N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() print(max(A[0], sum(i for i in A[:K] if i >= 0)))