import kotlin.math.max
import kotlin.math.min

fun main() {
    var nk= readLine()!!.split(" ").map { it.toInt() }
    var a= readLine()!!.split(" ").map { it.toLong() }
    var ans:Long=9223372036854775807
    for (i in 0 until Math.pow(2.toDouble(), nk[0].toDouble()).toInt()){
        var pre:Long=0
        var sum:Long=0
        var hot=0
        for (j in 0 until nk[0]){
            if(i.shr(j)%2==1){
                if (pre>=a[j]){
                    sum+=pre-a[j]+1
                }
                pre= max(pre+1, a[j])
                hot++
            }
            pre= max(pre, a[j])
        }
        if(hot>=nk[1]) ans= min(ans, sum)
    }
    println(ans)
}