n, k = map(int, input().split())
spi = list(map(int, input().split()))
ans = 0
def rec(spis, k):
    if (len(spis)==0 and k==0): return 0
    if (k<=0 or len(spis)==0): return -9999
    n = len(spis)
    ans = 0
    for mask in range(1,1 << n):
            sp = spis.copy()
            now = 0
            sg = 1
            cur = bin(mask).count('1')
            for i in range(n-1, -1, -1):
                if (mask & (1 << i)):
                    now =max(sp[i]+cur, now)
                    cur-=1
                    sp.pop(i)
            ans = max(ans, rec(sp, k-1) + now)
    return ans

for mask in range (1,1<<n):
        cur = bin(mask).count('1')
        sp = spi.copy()
        now = 0
        for i in range(n-1, -1, -1):
            if (mask & (1<<i)):
                now=max(spi[i]+cur, now)
                cur-=1
                sp.pop(i)
        ans = max(ans, rec(sp, k-1)+now)
print(ans)
