import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    val k = sc.nextInt()
    val n = s.length
    val dp0 = Array(n + 1) { Array(k + 2) { 0 } }   //n以下であることが未確定
    val dp1 = Array(n + 1) { Array(k + 2) { 0 } }   //n以下であることが確定
    dp0[0][0] = 1
    for (i in 0 until n) {
        for (j in 0..k) {
            val lim = s[i] - '0'
            if (lim > 0) {
                dp1[i + 1][j] += dp0[i][j] + dp1[i][j]      //0を追加
                dp0[i + 1][j + 1] += dp0[i][j]              //i桁目を追加
                for (d in 1 until lim) {
                    dp1[i + 1][j + 1] += dp0[i][j]          //i桁目より小さい数を追加
                }
                for (d in 1..9) {
                    dp1[i + 1][j + 1] += dp1[i][j]          //任意の数字を追加
                }
            } else {
                dp0[i + 1][j] += dp0[i][j]
                dp1[i + 1][j] += dp1[i][j]
            }
        }
    }
    println(dp0[n][k] + dp1[n][k])
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}