import sys

from itertools import combinations



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60





def main():

    N, K, *A = list(map(int, read().split()))



    ans = INF

    for comb in combinations(list(range(1, N)), K - 1):

        included = [False] * N

        for i in comb:

            included[i] = True



        total = 0

        max_height = A[0]

        for i, a in enumerate(A[1:], 1):

            if a <= max_height:

                if included[i]:

                    total += max_height - a + 1

                    max_height += 1

            else:

                max_height = a



        if ans > total:

            ans = total



    print(ans)



    return





if __name__ == '__main__':

    main()

import sys

from itertools import combinations



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60





def main():

    N, K, *A = list(map(int, read().split()))



    ans = INF

    for comb in combinations(list(range(1, N)), K - 1):

        included = set(comb)

        total = 0

        max_height = A[0]

        for i, a in enumerate(A[1:], 1):

            if a <= max_height:

                if i in included:

                    total += max_height - a + 1

                    max_height += 1

            else:

                max_height = a



        if ans > total:

            ans = total



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys
from itertools import combinations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60


def main():
    N, K, *A = list(map(int, read().split()))
    ans = INF
    for comb in combinations(list(range(1, N)), K - 1):
        included = [False] * N
        for i in comb:
            included[i] = True
        total = 0
        max_height = A[0]
        for i, a in enumerate(A[1:], 1):
            if a <= max_height:
                if included[i]:
                    total += max_height - a + 1
                    max_height += 1
            else:
                max_height = a
        if ans > total:
            ans = total
    print(ans)
    return


if __name__ == "__main__":
    main()

import sys
from itertools import combinations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60


def main():
    N, K, *A = list(map(int, read().split()))
    ans = INF
    for comb in combinations(list(range(1, N)), K - 1):
        included = set(comb)
        total = 0
        max_height = A[0]
        for i, a in enumerate(A[1:], 1):
            if a <= max_height:
                if i in included:
                    total += max_height - a + 1
                    max_height += 1
            else:
                max_height = a
        if ans > total:
            ans = total
    print(ans)
    return


if __name__ == "__main__":
    main()

-        included = [False] * N -        for i in comb: -            included[i] = True +        included = set(comb) -                if included[i]: +                if i in included: