import itertools

n, k = map(int, input().split())
a = list(map(int, input().split()))
best = 0
for el in itertools.product(range(k), repeat=n):
    ans = 0
    b = [[] for _ in range(k)]
    for i in range(n):
        b[el[i]].append(a[i])
    if any([len(b[bi]) == 0 for bi in range(k)]):
        continue
    for bi in range(k):
        ans += max(b[bi]) + b[bi].index(max(b[bi])) + 1
    if ans > best:
        best = ans
        #print(el)
    #print(el, ans)
print(best)
