n, k = list(map(int, input().split()))

buildings = list(map(int, input().split()))



ans = float('inf')

for i in range(2 ** n):

    res = 0

    cnt = 0

    prev_build = buildings[0]

    for j in range(n):

        if (i >> j) & 1 == 1:

            cnt += 1

            if prev_build >= buildings[j] and not j == 0:

                res += ((prev_build + 1) - buildings[j])

                prev_build = prev_build + 1

            else:

                prev_build = buildings[j]

        else:

            if prev_build < buildings[j]:

                prev_build = buildings[j]



    if cnt == k:

        ans = min(ans, res)



print(ans)
n, k = list(map(int, input().split()))

buildings = list(map(int, input().split()))



ans = float('inf')

for i in range(2 ** n):

    res = 0

    cnt = 1

    prev_build = buildings[0]

    # 高くするビルをbitで管理

    for j in range(1, n):

        if (i >> j) & 1:

            cnt += 1

            if prev_build >= buildings[j]:

                res += prev_build - buildings[j] + 1

                prev_build += 1

            else:

                prev_build = buildings[j]

        else:

            if prev_build < buildings[j]:

                cnt += 1

                prev_build = buildings[j]



    if cnt >= k:

        ans = min(ans, res)



print(ans)

n, k = list(map(int, input().split()))
buildings = list(map(int, input().split()))
ans = float("inf")
for i in range(2**n):
    res = 0
    cnt = 0
    prev_build = buildings[0]
    for j in range(n):
        if (i >> j) & 1 == 1:
            cnt += 1
            if prev_build >= buildings[j] and not j == 0:
                res += (prev_build + 1) - buildings[j]
                prev_build = prev_build + 1
            else:
                prev_build = buildings[j]
        else:
            if prev_build < buildings[j]:
                prev_build = buildings[j]
    if cnt == k:
        ans = min(ans, res)
print(ans)

n, k = list(map(int, input().split()))
buildings = list(map(int, input().split()))
ans = float("inf")
for i in range(2**n):
    res = 0
    cnt = 1
    prev_build = buildings[0]
    # 高くするビルをbitで管理
    for j in range(1, n):
        if (i >> j) & 1:
            cnt += 1
            if prev_build >= buildings[j]:
                res += prev_build - buildings[j] + 1
                prev_build += 1
            else:
                prev_build = buildings[j]
        else:
            if prev_build < buildings[j]:
                cnt += 1
                prev_build = buildings[j]
    if cnt >= k:
        ans = min(ans, res)
print(ans)

-    cnt = 0 +    cnt = 1 -    for j in range(n): -        if (i >> j) & 1 == 1: +    # 高くするビルをbitで管理 +    for j in range(1, n): +        if (i >> j) & 1: -            if prev_build >= buildings[j] and not j == 0: -                res += (prev_build + 1) - buildings[j] -                prev_build = prev_build + 1 +            if prev_build >= buildings[j]: +                res += prev_build - buildings[j] + 1 +                prev_build += 1 +                cnt += 1 -    if cnt == k: +    if cnt >= k: