N, K = list(map(int, input().split()))

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



ans = pow(10, 18)



for i in range(2 ** N):

    cost = 0

    cnt = 0

    highest = 0

    for j in range(N):

        if (i >> j) & 1:

            cnt += 1

            if highest >= a[j]:

                cost += highest - a[j] + 1

                highest += 1



        highest = max(highest, a[j])

    if cnt >= K:

        ans = min(cost, ans)



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

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



cost = 10 ** 18

for i in range(2 ** (n - 1)):

    num = 0

    c = 0

    prev = a[0]

    for j in range(n - 1):

        if i >> j & 1:

            num += 1

            if a[j + 1] <= prev:

                c += prev - a[j + 1] + 1

                prev += 1

        prev = max(prev, a[j + 1])

    if num >= k - 1:

        cost = min(c, cost)

print(cost)
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = pow(10, 18)
for i in range(2**N):
    cost = 0
    cnt = 0
    highest = 0
    for j in range(N):
        if (i >> j) & 1:
            cnt += 1
            if highest >= a[j]:
                cost += highest - a[j] + 1
                highest += 1
        highest = max(highest, a[j])
    if cnt >= K:
        ans = min(cost, ans)
print(ans)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = 10**18
for i in range(2 ** (n - 1)):
    num = 0
    c = 0
    prev = a[0]
    for j in range(n - 1):
        if i >> j & 1:
            num += 1
            if a[j + 1] <= prev:
                c += prev - a[j + 1] + 1
                prev += 1
        prev = max(prev, a[j + 1])
    if num >= k - 1:
        cost = min(c, cost)
print(cost)

-N, K = list(map(int, input().split())) +n, k = list(map(int, input().split())) -ans = pow(10, 18) -for i in range(2**N): -    cost = 0 -    cnt = 0 -    highest = 0 -    for j in range(N): -        if (i >> j) & 1: -            cnt += 1 -            if highest >= a[j]: -                cost += highest - a[j] + 1 -                highest += 1 -        highest = max(highest, a[j]) -    if cnt >= K: -        ans = min(cost, ans) -print(ans) +cost = 10**18 +for i in range(2 ** (n - 1)): +    num = 0 +    c = 0 +    prev = a[0] +    for j in range(n - 1): +        if i >> j & 1: +            num += 1 +            if a[j + 1] <= prev: +                c += prev - a[j + 1] + 1 +                prev += 1 +        prev = max(prev, a[j + 1]) +    if num >= k - 1: +        cost = min(c, cost) +print(cost)