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

a = [int(i) for i in input().split()]

ans = float("INF")

for i in range(1<<N):

    cnt = 0

    tmp = a[:]

    m = tmp[0]

    for j in range(1,N):

        if i >> j & 1 and m >= tmp[j]:

            cnt += m - tmp[j] + 1

            tmp[j] = m + 1

        m = max(m,tmp[j])

    color = 1

    m = tmp[0]

    for j in range(1,N):

        if tmp[j] > m:

            color += 1

            m = tmp[j]

    if color >= K: ans = min(ans,cnt)

print(ans)
from itertools import combinations as comb

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

a = [int(i) for i in input().split()]

ans = float("INF")



for c in comb(list(range(1,N)),K-1):

    cnt = 0

    color = 0

    mh = a[0]

    for i in range(1,N):

        if i == c[color]:

            cnt += max(mh-a[i]+1,0)

            color += 1

            if color == K-1: break

            mh = max(mh+1,a[i])

        else:

            mh = max(mh,a[i])

    ans = min(cnt ,ans)

print(ans)
N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
ans = float("INF")
for i in range(1 << N):
    cnt = 0
    tmp = a[:]
    m = tmp[0]
    for j in range(1, N):
        if i >> j & 1 and m >= tmp[j]:
            cnt += m - tmp[j] + 1
            tmp[j] = m + 1
        m = max(m, tmp[j])
    color = 1
    m = tmp[0]
    for j in range(1, N):
        if tmp[j] > m:
            color += 1
            m = tmp[j]
    if color >= K:
        ans = min(ans, cnt)
print(ans)

from itertools import combinations as comb

N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
ans = float("INF")
for c in comb(list(range(1, N)), K - 1):
    cnt = 0
    color = 0
    mh = a[0]
    for i in range(1, N):
        if i == c[color]:
            cnt += max(mh - a[i] + 1, 0)
            color += 1
            if color == K - 1:
                break
            mh = max(mh + 1, a[i])
        else:
            mh = max(mh, a[i])
    ans = min(cnt, ans)
print(ans)

+from itertools import combinations as comb + -for i in range(1 << N): +for c in comb(list(range(1, N)), K - 1): -    tmp = a[:] -    m = tmp[0] -    for j in range(1, N): -        if i >> j & 1 and m >= tmp[j]: -            cnt += m - tmp[j] + 1 -            tmp[j] = m + 1 -        m = max(m, tmp[j]) -    color = 1 -    m = tmp[0] -    for j in range(1, N): -        if tmp[j] > m: +    color = 0 +    mh = a[0] +    for i in range(1, N): +        if i == c[color]: +            cnt += max(mh - a[i] + 1, 0) -            m = tmp[j] -    if color >= K: -        ans = min(ans, cnt) +            if color == K - 1: +                break +            mh = max(mh + 1, a[i]) +        else: +            mh = max(mh, a[i]) +    ans = min(cnt, ans)