import itertools N, K = map(int, input().split()) A = tuple(map(int, input().split())) A = [x if x > 0 else 0 for x in A] yummy = [sum(x) for x in itertools.combinations(A, K)] print(max(yummy))