fun main(args: Array<String>) {
    var s = readLine()!!.map { it.toInt()-48 }
    var K = readLine()!!.toInt()
    val n = s.size
    var result = 0.toLong()
    when {
        K>n -> result = 0
        K==3 -> {
            result += (s[0]-1)*(n-1)*(n-2)*9*9/2
            result += (s[1]-1)*(n-2)*9
            result += (n-2)*(n-3) * 9*9/2
            result += s[2]
            result += (n-3) * 9
            result += (n-1)*(n-2)*(n-3)*9*9*9/6
        }
        K==2 -> {
            result += (s[0]-1)*(n-1)*9
            result += (s[1] + (n-2)*9)
            result += ((n-1)*(n-2)*9*9/2)
        }
        K==1 -> {
            result += s[0]
            result += 9*(n-1)
        }
    }
    println(result)
}