# A N, K = list(map(int, input().split())) As = list(map(int, input().split())) positives = [a for a in As if a >= 0] negatives = [a for a in As if a < 0] if positives: selected = sorted(positives) else: selected = [sorted(negatives)[-1]] selected = selected[-min(K, len(selected)):] print(sum(selected))