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

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



ans=10**20

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

    I=i

    T=a[0]

    C=1

    cost=0

    S=[]

    for s in range(N-1):

        if I//(2**(N-2-s))==1:

            S.append("1")

        else:

            S.append("0")

        I%=(2**(N-2-s))

    #print(S)

    for j in range(len(S)):

        if S[j]=="1":

            if a[j+1]>T:

                T=a[j+1]

                C+=1

            else:

                cost+=T+1-a[j+1]

                T+=1

                C+=1

        else:

            if a[j+1]>T:

                T=a[j+1]

                C+=1

    if C>=K and ans>cost:

        ans=cost

    #print(C,cost,S)

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

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



import itertools

l=[i for i in range(1,N)]

Arr=list(itertools.combinations(l,K-1)) #Lの中から2個



#print(Arr)



ans=10**12

for i in Arr:

    cost=0

    hight=L[0]

    for j in range(1,N):

        if j in i:

            if hight<L[j]:

                hight=L[j]

            else:

                cost+=(hight-L[j]+1)

                hight+=1

        else:

            hight=max(hight,L[j])

    if ans>cost:

        ans=cost

print(ans)
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 10**20
for i in range(2 ** (N - 1)):
    I = i
    T = a[0]
    C = 1
    cost = 0
    S = []
    for s in range(N - 1):
        if I // (2 ** (N - 2 - s)) == 1:
            S.append("1")
        else:
            S.append("0")
        I %= 2 ** (N - 2 - s)
    # print(S)
    for j in range(len(S)):
        if S[j] == "1":
            if a[j + 1] > T:
                T = a[j + 1]
                C += 1
            else:
                cost += T + 1 - a[j + 1]
                T += 1
                C += 1
        else:
            if a[j + 1] > T:
                T = a[j + 1]
                C += 1
    if C >= K and ans > cost:
        ans = cost
    # print(C,cost,S)
print(ans)

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

l = [i for i in range(1, N)]
Arr = list(itertools.combinations(l, K - 1))  # Lの中から2個
# print(Arr)
ans = 10**12
for i in Arr:
    cost = 0
    hight = L[0]
    for j in range(1, N):
        if j in i:
            if hight < L[j]:
                hight = L[j]
            else:
                cost += hight - L[j] + 1
                hight += 1
        else:
            hight = max(hight, L[j])
    if ans > cost:
        ans = cost
print(ans)

-a = list(map(int, input().split())) -ans = 10**20 -for i in range(2 ** (N - 1)): -    I = i -    T = a[0] -    C = 1 +L = list(map(int, input().split())) +import itertools + +l = [i for i in range(1, N)] +Arr = list(itertools.combinations(l, K - 1))  # Lの中から2個 +# print(Arr) +ans = 10**12 +for i in Arr: -    S = [] -    for s in range(N - 1): -        if I // (2 ** (N - 2 - s)) == 1: -            S.append("1") +    hight = L[0] +    for j in range(1, N): +        if j in i: +            if hight < L[j]: +                hight = L[j] +            else: +                cost += hight - L[j] + 1 +                hight += 1 -            S.append("0") -        I %= 2 ** (N - 2 - s) -    # print(S) -    for j in range(len(S)): -        if S[j] == "1": -            if a[j + 1] > T: -                T = a[j + 1] -                C += 1 -            else: -                cost += T + 1 - a[j + 1] -                T += 1 -                C += 1 -        else: -            if a[j + 1] > T: -                T = a[j + 1] -                C += 1 -    if C >= K and ans > cost: +            hight = max(hight, L[j]) +    if ans > cost: -    # print(C,cost,S)