There are N buildings along the line. The i-th building from the left is colored in color i, and its height is currently a_i meters.   Chokudai is a mayor of the city, and he loves colorful thigs. And now he wants to see at least K buildings from the left.      You can increase height of buildings, but it costs 1 yens to increase 1 meters. It means you cannot make building that height is not integer.   You cannot decrease height of buildings.   Calculate the minimum cost of satisfying Chokudai's objective.   Note: "Building i can see from the left" means there are no j exists that (height of building j) ≥ (height of building i) and j < i.
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#n = int(input())
n, k = map(int, sys.stdin.readline().split())
#n = input()
a = list(map(int, sys.stdin.readline().split()))

l = list(itertools.combinations(range(n), k))
print(a)
print(l)

ans = 10 ** 18
for i in range(len(l)):
    cost = 0
    m1 = 0
    p = 20
    for j in range(l[i][0]+1):
        if a[j] > m1:
            m1 = a[j]
            p = j

        if j == l[i][0]:
            if m1 == a[j]:
                if p != j:
                    cost += 1
            else:
                cost += (m1 - a[j] + 1)

    
    r = 1
    if len(l[0]) >= 2:
        q = l[i][r]
    else:
        q = 20

    m2 = a[l[i][0]] + cost

    for j in range(l[i][0]+1, n):
        if j == q:
            if a[j] > m2:
                m2 = a[j]
            else:
                m2 += 1
                cost += (m2 - a[j])

            if r != len(l[0])-1:
                r += 1
                q = l[i][r]
            
        else:
            if a[j] > m2:
                cost += a[j] - m2
                m2 = a[j]
                

    if cost < ans:
        ans = cost


print(ans)
                
        


















import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#n = int(input())
n, k = map(int, sys.stdin.readline().split())
#n = input()
a = list(map(int, sys.stdin.readline().split()))

l = list(itertools.combinations(range(n), k))

ans = 10 ** 18
for i in range(len(l)):
    cost = 0
    m1 = 0
    p = 20
    for j in range(l[i][0]+1):
        if a[j] > m1:
            m1 = a[j]
            p = j

        if j == l[i][0]:
            if m1 == a[j]:
                if p != j:
                    cost += 1
            else:
                cost += (m1 - a[j] + 1)

    
    r = 1
    if len(l[0]) >= 2:
        q = l[i][r]
    else:
        q = 20

    m2 = a[l[i][0]] + cost

    for j in range(l[i][0]+1, n):
        if j == q:
            if a[j] > m2:
                m2 = a[j]
            else:
                m2 += 1
                cost += (m2 - a[j])

            if r != len(l[0])-1:
                r += 1
                q = l[i][r]
            
        else:
            if a[j] > m2:
                cost += a[j] - m2
                m2 = a[j]
                

    if cost < ans:
        ans = cost


print(ans)
                
        

















