fun main(args: Array<String>) {
    val N = readLine()!!
    val K = readLine()!!.toInt()
    val L = N.length
    val dp0 = Array(L + 1) { IntArray(K + 1) }
    val dp1 = Array(L + 1) { IntArray(K + 1) }
    dp0[0][0] = 0
    dp0[0][1] = 0
    dp1[0][0] = 1
    dp1[0][1] = 0
    (1..L).forEach { l ->
        val n = N[l - 1] - '0'
        val a = (0 until n).count()
        dp0[l][0] = if (N.take(l).all { it=='0' }) 0 else 1
        dp1[l][0] = if (N.take(l).all { it=='0' }) 1 else 0
        (1..K).forEach { k ->
            dp0[l][k] = dp0[l-1][k] + dp0[l-1][k-1] * 9 + if (n != 0) dp1[l-1][k-1] * (a-1) + dp1[l-1][k] else 0
            dp1[l][k] = if (n == 0) dp1[l-1][k] else dp1[l-1][k-1]
        }
    }
    print(dp0[L][K] + dp1[L][K])
}