def solve(n,k) :

    if n <= 9 and k == 1 :

        return n

    elif n <= 9 and k >= 2 :

        return 0

    elif k == 0:

        return 1

    else :

        m = n //10

        r = n % 10

        return  r * solve(m,k-1) + (9 - r) * solve(m-1,k-1) + solve(m,k)



n = int(eval(input()))

k = int(eval(input()))

print((solve(n,k)))
N = eval(input())

K = int(eval(input()))

m = len(N)

dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)]

dp[0][0][0] = 1



for i in range(1, m + 1):

    l = int(N[i - 1])

    for k in range(K + 1):

        dp[i][1][k] += dp[i - 1][1][k]

        if l != 0:

            dp[i][1][k] += dp[i - 1][0][k]

        else:

            dp[i][0][k] += dp[i - 1][0][k]

        if k - 1 >= 0:

            dp[i][1][k] += 9 * dp[i - 1][1][k - 1]

            if l != 0:

                dp[i][0][k] += dp[i - 1][0][k - 1]

                dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1]



print((dp[m][0][K] + dp[m][1][K]))

def solve(n, k):
    if n <= 9 and k == 1:
        return n
    elif n <= 9 and k >= 2:
        return 0
    elif k == 0:
        return 1
    else:
        m = n // 10
        r = n % 10
        return r * solve(m, k - 1) + (9 - r) * solve(m - 1, k - 1) + solve(m, k)


n = int(eval(input()))
k = int(eval(input()))
print((solve(n, k)))

N = eval(input())
K = int(eval(input()))
m = len(N)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)]
dp[0][0][0] = 1
for i in range(1, m + 1):
    l = int(N[i - 1])
    for k in range(K + 1):
        dp[i][1][k] += dp[i - 1][1][k]
        if l != 0:
            dp[i][1][k] += dp[i - 1][0][k]
        else:
            dp[i][0][k] += dp[i - 1][0][k]
        if k - 1 >= 0:
            dp[i][1][k] += 9 * dp[i - 1][1][k - 1]
            if l != 0:
                dp[i][0][k] += dp[i - 1][0][k - 1]
                dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1]
print((dp[m][0][K] + dp[m][1][K]))

-def solve(n, k): -    if n <= 9 and k == 1: -        return n -    elif n <= 9 and k >= 2: -        return 0 -    elif k == 0: -        return 1 -    else: -        m = n // 10 -        r = n % 10 -        return r * solve(m, k - 1) + (9 - r) * solve(m - 1, k - 1) + solve(m, k) - - -n = int(eval(input())) -k = int(eval(input())) -print((solve(n, k))) +N = eval(input()) +K = int(eval(input())) +m = len(N) +dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)] +dp[0][0][0] = 1 +for i in range(1, m + 1): +    l = int(N[i - 1]) +    for k in range(K + 1): +        dp[i][1][k] += dp[i - 1][1][k] +        if l != 0: +            dp[i][1][k] += dp[i - 1][0][k] +        else: +            dp[i][0][k] += dp[i - 1][0][k] +        if k - 1 >= 0: +            dp[i][1][k] += 9 * dp[i - 1][1][k - 1] +            if l != 0: +                dp[i][0][k] += dp[i - 1][0][k - 1] +                dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1] +print((dp[m][0][K] + dp[m][1][K]))