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

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



ans=float("inf")

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

    num=format(i,"b").zfill(n)

    point=0

    if num.count("1")!=k:continue

    highest=A[0]

    for j in range(1,n):

        if highest>=A[j] and  num[j]=="1":

            point +=highest-A[j]+1

            highest +=1

        highest=max(highest,A[j])

    ans=min(ans,point)



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

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



ans=float("inf")

for i in range(2**n):

    num=format(i,"b").zfill(n)

    if num.count("1")!=k:continue

    height,money=0,0

    for j in range(n):

        if num[j]=="1":

            if A[j]<=height:

                money +=height-A[j]+1

                height +=1

            else:height=A[j]

        else:

            if A[j]>height:height=A[j]

    ans=min(ans,money)

print(ans)
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = float("inf")
for i in range(1, 2**n):
    num = format(i, "b").zfill(n)
    point = 0
    if num.count("1") != k:
        continue
    highest = A[0]
    for j in range(1, n):
        if highest >= A[j] and num[j] == "1":
            point += highest - A[j] + 1
            highest += 1
        highest = max(highest, A[j])
    ans = min(ans, point)
print(ans)

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = float("inf")
for i in range(2**n):
    num = format(i, "b").zfill(n)
    if num.count("1") != k:
        continue
    height, money = 0, 0
    for j in range(n):
        if num[j] == "1":
            if A[j] <= height:
                money += height - A[j] + 1
                height += 1
            else:
                height = A[j]
        else:
            if A[j] > height:
                height = A[j]
    ans = min(ans, money)
print(ans)

-for i in range(1, 2**n): +for i in range(2**n): -    point = 0 -    highest = A[0] -    for j in range(1, n): -        if highest >= A[j] and num[j] == "1": -            point += highest - A[j] + 1 -            highest += 1 -        highest = max(highest, A[j]) -    ans = min(ans, point) +    height, money = 0, 0 +    for j in range(n): +        if num[j] == "1": +            if A[j] <= height: +                money += height - A[j] + 1 +                height += 1 +            else: +                height = A[j] +        else: +            if A[j] > height: +                height = A[j] +    ans = min(ans, money)