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

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

ans = 10**19



for bit in range(2**N):

    if bin(bit).count('1') != K:

        continue



    cost, height = 0, 0

    for i in range(N):

        if bit & (1 << i) == 0:

            if height < a[i]:

                height = a[i]

            continue

        if height >= a[i]:

            cost += height - a[i] + 1

            height += 1

        else:

            height = a[i]



    if ans > cost:

        ans = cost



print(ans)

def main():

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

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



    ans = 10**19



    for bit in range(2**n):

        if bin(bit).count('1') != k:

            continue

        tmp = 0

        max_hight = 0

        for i in range(n):

            if bit & (1 << i) == 0:

                if max_hight < num_list[i]:

                    max_hight = num_list[i]

                # max_hight = max(max_hight, num_list[i])

                continue

            if max_hight >= num_list[i]:

                tmp += max_hight - num_list[i] + 1

                max_hight += 1

            else:

                max_hight = num_list[i]

            

        if ans > tmp:

            ans = tmp

        # ans = min(ans, tmp)

    

    print(ans)



if __name__ == '__main__':

    main()
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 10**19
for bit in range(2**N):
    if bin(bit).count("1") != K:
        continue
    cost, height = 0, 0
    for i in range(N):
        if bit & (1 << i) == 0:
            if height < a[i]:
                height = a[i]
            continue
        if height >= a[i]:
            cost += height - a[i] + 1
            height += 1
        else:
            height = a[i]
    if ans > cost:
        ans = cost
print(ans)

def main():
    n, k = list(map(int, input().split()))
    num_list = list(map(int, input().split()))
    ans = 10**19
    for bit in range(2**n):
        if bin(bit).count("1") != k:
            continue
        tmp = 0
        max_hight = 0
        for i in range(n):
            if bit & (1 << i) == 0:
                if max_hight < num_list[i]:
                    max_hight = num_list[i]
                # max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                tmp += max_hight - num_list[i] + 1
                max_hight += 1
            else:
                max_hight = num_list[i]
        if ans > tmp:
            ans = tmp
        # ans = min(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

-N, K = list(map(int, input().split())) -a = list(map(int, input().split())) -ans = 10**19 -for bit in range(2**N): -    if bin(bit).count("1") != K: -        continue -    cost, height = 0, 0 -    for i in range(N): -        if bit & (1 << i) == 0: -            if height < a[i]: -                height = a[i] +def main(): +    n, k = list(map(int, input().split())) +    num_list = list(map(int, input().split())) +    ans = 10**19 +    for bit in range(2**n): +        if bin(bit).count("1") != k: -        if height >= a[i]: -            cost += height - a[i] + 1 -            height += 1 -        else: -            height = a[i] -    if ans > cost: -        ans = cost -print(ans) +        tmp = 0 +        max_hight = 0 +        for i in range(n): +            if bit & (1 << i) == 0: +                if max_hight < num_list[i]: +                    max_hight = num_list[i] +                # max_hight = max(max_hight, num_list[i]) +                continue +            if max_hight >= num_list[i]: +                tmp += max_hight - num_list[i] + 1 +                max_hight += 1 +            else: +                max_hight = num_list[i] +        if ans > tmp: +            ans = tmp +        # ans = min(ans, tmp) +    print(ans) + + +if __name__ == "__main__": +    main()