import java.lang.Math.max
import java.lang.Math.min
import java.util.*

fun main(args: Array<String>) = p14()

fun p14() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val maxes = LongArray(n)
    maxes[0] = aList.first()
    for (i in 1 until n) maxes[i] = max(maxes[i - 1], aList[i])

    var answer = Long.MAX_VALUE

    for (i in 0 until (1L shl n)) {
        val bitSet = BitSet.valueOf(longArrayOf(i))
        if (bitSet.cardinality() != k) continue

        val filtered = aList.withIndex().filter { bitSet[it.index] }

        var sum = 0L
        var prevHeight = -1L

        for ((index, height) in filtered) {
            if (index != 0) prevHeight = max(prevHeight, maxes[index - 1])
            if (prevHeight >= height) {
                sum += (prevHeight - height) + 1
                prevHeight++
            } else {
                prevHeight = height
            }
        }
        answer = min(answer, sum)
    }

    println(answer)
}
