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

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

ans = 10 ** 10

if N==K:

    cost=0

    for i in range(1,N):

        if height[i-1]>=height[i]:

            cost+=height[i-1]-height[i]+1

            height[i]+=height[i-1]-height[i]+1

    print(cost)

    exit()

for i in range(2 ** N):

    count=1

    cost = 0

    height2 = height.copy()

    for j in range(N):

        if i >> j & 1:

            if j!=0:

                tarou=max(height2[:j])

                if height2[j]<=tarou:

                    cost+=tarou-height2[j]+1

                    height2[j]+=tarou-height2[j]+1

                    count+=1

                else:count+=1

    # zenkai=0

    # for x in range(1,N):

    #     if height2[zenkai] < height2[x]:

    #         count += 1

    #         zenkai=x

    if ans > cost and count >= K:

        ans = cost



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

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

height2=height.copy()

ans = 10 ** 10

if N==K:

    cost=0

    for i in range(1,N):

        tarou=max(height2[:i])

        if tarou>=height2[i]:

            cost+=tarou-height2[i]+1

            height2[i]=tarou+1

    print(cost)

    exit()

for i in range(2 ** N):

    cost = 0

    height2 = height.copy()

    if bin(i).count("1")==K:

        for j in range(1,N):

            if i >> j & 1:

                if N==K:

                    if height2[j-1]>=height2[j]:

                            cost+=height2[j-1]-height2[j]+1

                            height2[j]+=height2[j-1]-height2[j]+1

                else:

                    tarou=max(height2[:j])

                    if height2[j]<=tarou:

                        cost+=tarou-height2[j]+1

                        height2[j]=tarou+1



        if ans > cost:

            ans = cost



print(ans)
N, K = list(map(int, input().split()))
height = list(map(int, input().split()))
ans = 10**10
if N == K:
    cost = 0
    for i in range(1, N):
        if height[i - 1] >= height[i]:
            cost += height[i - 1] - height[i] + 1
            height[i] += height[i - 1] - height[i] + 1
    print(cost)
    exit()
for i in range(2**N):
    count = 1
    cost = 0
    height2 = height.copy()
    for j in range(N):
        if i >> j & 1:
            if j != 0:
                tarou = max(height2[:j])
                if height2[j] <= tarou:
                    cost += tarou - height2[j] + 1
                    height2[j] += tarou - height2[j] + 1
                    count += 1
                else:
                    count += 1
    # zenkai=0
    # for x in range(1,N):
    #     if height2[zenkai] < height2[x]:
    #         count += 1
    #         zenkai=x
    if ans > cost and count >= K:
        ans = cost
print(ans)

N, K = list(map(int, input().split()))
height = list(map(int, input().split()))
height2 = height.copy()
ans = 10**10
if N == K:
    cost = 0
    for i in range(1, N):
        tarou = max(height2[:i])
        if tarou >= height2[i]:
            cost += tarou - height2[i] + 1
            height2[i] = tarou + 1
    print(cost)
    exit()
for i in range(2**N):
    cost = 0
    height2 = height.copy()
    if bin(i).count("1") == K:
        for j in range(1, N):
            if i >> j & 1:
                if N == K:
                    if height2[j - 1] >= height2[j]:
                        cost += height2[j - 1] - height2[j] + 1
                        height2[j] += height2[j - 1] - height2[j] + 1
                else:
                    tarou = max(height2[:j])
                    if height2[j] <= tarou:
                        cost += tarou - height2[j] + 1
                        height2[j] = tarou + 1
        if ans > cost:
            ans = cost
print(ans)

+height2 = height.copy() -        if height[i - 1] >= height[i]: -            cost += height[i - 1] - height[i] + 1 -            height[i] += height[i - 1] - height[i] + 1 +        tarou = max(height2[:i]) +        if tarou >= height2[i]: +            cost += tarou - height2[i] + 1 +            height2[i] = tarou + 1 -    count = 1 -    for j in range(N): -        if i >> j & 1: -            if j != 0: -                tarou = max(height2[:j]) -                if height2[j] <= tarou: -                    cost += tarou - height2[j] + 1 -                    height2[j] += tarou - height2[j] + 1 -                    count += 1 +    if bin(i).count("1") == K: +        for j in range(1, N): +            if i >> j & 1: +                if N == K: +                    if height2[j - 1] >= height2[j]: +                        cost += height2[j - 1] - height2[j] + 1 +                        height2[j] += height2[j - 1] - height2[j] + 1 -                    count += 1 -    # zenkai=0 -    # for x in range(1,N): -    #     if height2[zenkai] < height2[x]: -    #         count += 1 -    #         zenkai=x -    if ans > cost and count >= K: -        ans = cost +                    tarou = max(height2[:j]) +                    if height2[j] <= tarou: +                        cost += tarou - height2[j] + 1 +                        height2[j] = tarou + 1 +        if ans > cost: +            ans = cost