data class Relate(val x: Int, val y: Int)

fun main(args: Array<String>) {
    val (n, k) = readIntegerList()
    val aList = readIntegerList()

    var ans = Long.MAX_VALUE
    for (state in 0 until (1 shl n)) {
        if (Integer.bitCount(state) < k) {
            continue
        }

        var tmp = 0L
        var currentMaxHeight = 0
        for (i in 0 until n) {
            if (((state shr i) and 1) == 1) {
                if (aList[i] <= currentMaxHeight) {
                    tmp += currentMaxHeight - aList[i] + 1
                }
                currentMaxHeight = Math.max(currentMaxHeight + 1, aList[i])
            } else {
                currentMaxHeight = Math.max(currentMaxHeight, aList[i])
            }
        }

        ans = Math.min(ans, tmp)
    }

    println(ans)
}

//fun countOneBits(state: Int, bitLength: Int): Int {
//    var count = 0
//    for (i in 0 until bitLength) {
//        if (((state shr i) and 1) == 1) {
//            count++
//        }
//    }
//    return count
//}




fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
