# -*- coding: utf-8 -*-

# モジュールのインポート

import sys

import itertools



# 標準入力を取得

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

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



# 求解処理

ans = sys.maxsize

for buildings in itertools.combinations(list(range(N)), K):

    cost = 0

    highest = a[0] - 1

    for n in range(N):

        a_n = a[n]

        built = 0

        if n in buildings:

            built = max(highest - a_n + 1, 0)

            cost += built

        highest = max(highest, a_n + built)

    ans = min(ans, cost)



# 結果出力

print(ans)

# -*- coding: utf-8 -*-

# モジュールのインポート

import sys

import itertools





def get_input() -> tuple:

    """

    標準入力を取得する.



    Returns:\n

        tuple: 標準入力

    """

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

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



    return N, K, a





def main(N: int, K: int, a: list) -> None:

    """

    メイン処理.



    Args:\n

        N (int): 建物の個数(1 <= N <= 15)

        K (int): 色の数(1 <= K <= N)

        a (list): 高さ(1 <= a_i <= 10**9)

    """

    # 求解処理

    ans = sys.maxsize

    for buildings in itertools.combinations(list(range(N)), K):

        cost = 0

        highest = a[0] - 1

        for n in range(N):

            a_n = a[n]

            built = 0

            if n in buildings:

                built = max(highest - a_n + 1, 0)

                cost += built

            highest = max(highest, a_n + built)

        ans = min(ans, cost)



    # 結果出力

    print(ans)





if __name__ == "__main__":

    # 標準入力を取得

    N, K, a = get_input()



    # メイン処理

    main(N, K, a)

# -*- coding: utf-8 -*-
# モジュールのインポート
import sys
import itertools

# 標準入力を取得
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
# 求解処理
ans = sys.maxsize
for buildings in itertools.combinations(list(range(N)), K):
    cost = 0
    highest = a[0] - 1
    for n in range(N):
        a_n = a[n]
        built = 0
        if n in buildings:
            built = max(highest - a_n + 1, 0)
            cost += built
        highest = max(highest, a_n + built)
    ans = min(ans, cost)
# 結果出力
print(ans)

# -*- coding: utf-8 -*-
# モジュールのインポート
import sys
import itertools


def get_input() -> tuple:
    """
    標準入力を取得する.
    Returns:\n
        tuple: 標準入力
    """
    N, K = list(map(int, input().split()))
    a = list(map(int, input().split()))
    return N, K, a


def main(N: int, K: int, a: list) -> None:
    """
    メイン処理.
    Args:\n
        N (int): 建物の個数(1 <= N <= 15)
        K (int): 色の数(1 <= K <= N)
        a (list): 高さ(1 <= a_i <= 10**9)
    """
    # 求解処理
    ans = sys.maxsize
    for buildings in itertools.combinations(list(range(N)), K):
        cost = 0
        highest = a[0] - 1
        for n in range(N):
            a_n = a[n]
            built = 0
            if n in buildings:
                built = max(highest - a_n + 1, 0)
                cost += built
            highest = max(highest, a_n + built)
        ans = min(ans, cost)
    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, K, a = get_input()
    # メイン処理
    main(N, K, a)

-# 標準入力を取得 -N, K = list(map(int, input().split())) -a = list(map(int, input().split())) -# 求解処理 -ans = sys.maxsize -for buildings in itertools.combinations(list(range(N)), K): -    cost = 0 -    highest = a[0] - 1 -    for n in range(N): -        a_n = a[n] -        built = 0 -        if n in buildings: -            built = max(highest - a_n + 1, 0) -            cost += built -        highest = max(highest, a_n + built) -    ans = min(ans, cost) -# 結果出力 -print(ans) + +def get_input() -> tuple: +    """ +    標準入力を取得する. +    Returns:\n +        tuple: 標準入力 +    """ +    N, K = list(map(int, input().split())) +    a = list(map(int, input().split())) +    return N, K, a + + +def main(N: int, K: int, a: list) -> None: +    """ +    メイン処理. +    Args:\n +        N (int): 建物の個数(1 <= N <= 15) +        K (int): 色の数(1 <= K <= N) +        a (list): 高さ(1 <= a_i <= 10**9) +    """ +    # 求解処理 +    ans = sys.maxsize +    for buildings in itertools.combinations(list(range(N)), K): +        cost = 0 +        highest = a[0] - 1 +        for n in range(N): +            a_n = a[n] +            built = 0 +            if n in buildings: +                built = max(highest - a_n + 1, 0) +                cost += built +            highest = max(highest, a_n + built) +        ans = min(ans, cost) +    # 結果出力 +    print(ans) + + +if __name__ == "__main__": +    # 標準入力を取得 +    N, K, a = get_input() +    # メイン処理 +    main(N, K, a)