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