import numpy as np

from itertools import combinations 

INF = int(1e9)*15

def main():

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

    a = np.array(input().split(), np.int32)

    c = np.array([int(i) for i in range(1, n)])

    ans = INF

    for comb in combinations(c, k-1):

        s = set(comb)

        mx = a[0]

        cost = 0

        for i in range(n):

            if i in s:

                if a[i] > mx:

                    mx = a[i]

                    continue

                else:

                    mx += 1

                    cost += mx-a[i] 

                    continue

            mx = max(mx, a[i])

        ans = min(cost, ans)

    print(ans)

if __name__ == '__main__':

    main()

from itertools import combinations 

INF = int(1e9)*15

def main():

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

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

    c = [int(i) for i in range(1, n)]

    ans = INF

    for comb in combinations(c, k-1):

        s = set(comb)

        mx = a[0]

        cost = 0

        for i in range(n):

            if i in s:

                if a[i] > mx:

                    mx = a[i]

                    continue

                else:

                    mx += 1

                    cost += mx-a[i] 

                    continue

            mx = max(mx, a[i])

        ans = min(cost, ans)

    print(ans)

if __name__ == '__main__':

    main()

import numpy as np
from itertools import combinations

INF = int(1e9) * 15


def main():
    n, k = list(map(int, input().split()))
    a = np.array(input().split(), np.int32)
    c = np.array([int(i) for i in range(1, n)])
    ans = INF
    for comb in combinations(c, k - 1):
        s = set(comb)
        mx = a[0]
        cost = 0
        for i in range(n):
            if i in s:
                if a[i] > mx:
                    mx = a[i]
                    continue
                else:
                    mx += 1
                    cost += mx - a[i]
                    continue
            mx = max(mx, a[i])
        ans = min(cost, ans)
    print(ans)


if __name__ == "__main__":
    main()

from itertools import combinations

INF = int(1e9) * 15


def main():
    n, k = list(map(int, input().split()))
    a = [int(i) for i in input().split()]
    c = [int(i) for i in range(1, n)]
    ans = INF
    for comb in combinations(c, k - 1):
        s = set(comb)
        mx = a[0]
        cost = 0
        for i in range(n):
            if i in s:
                if a[i] > mx:
                    mx = a[i]
                    continue
                else:
                    mx += 1
                    cost += mx - a[i]
                    continue
            mx = max(mx, a[i])
        ans = min(cost, ans)
    print(ans)


if __name__ == "__main__":
    main()

-import numpy as np -    a = np.array(input().split(), np.int32) -    c = np.array([int(i) for i in range(1, n)]) +    a = [int(i) for i in input().split()] +    c = [int(i) for i in range(1, n)]