fun main(args: Array<String>) {
    val s = readLine()!!
    val k = readLine()!!.toInt()
    val n = s.length

    fun combination(a: Int, b: Int): Long {
        if (a < b) return 0
        var r = 1L
        for (i in 0 until b) {
            r *= (a - i)
        }
        for (i in 1..b) {
            r /= i
        }
        return r
    }

    fun pow9(p: Int): Long {
        var r = 1L
        repeat(p) { r *= 9 }
        return r
    }

    var ans = 0L
    fun dfs(i: Int, r : Int) {
        if (r == 0) {
            ans++
            return
        }
        if (i >= n) return

        val d = s[i] - '0'
        for (x in 0..d) {
            if (x == d) {
                if (d > 0) dfs(i + 1, r - 1)
                else dfs(i + 1, r)
            } else {
                if (x > 0) {
                    ans += combination(n - i - 1, r - 1) * pow9(r - 1)
                } else {
                    ans += combination(n - i - 1, r) * pow9(r)
                }
            }
        }
    }
    dfs(0, k)
    println(ans)
}