N, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) if K == 1: print(A[0]) elif A[K - 1] < 0: print(sum(filter(lambda x: x >= 0, A))) else: print(sum(A[:K]))