import numpy as np



N = eval(input())

K = int(eval(input()))



dp = np.zeros((len(N)+1, K+1), np.int64)

dp[1, 1] = 1

for d in range(1, len(N)):

    dp[d+1] = dp[d]

    dp[d+1, 1:] += dp[d, :-1]



ans = 0

for i, c in enumerate(N):

    n = len(N)-i

    if c != '0':

        ans += np.sum(dp[:n, K]) * (9 ** K)

        ans += dp[n, K] * (int(c) - 1) * (9 ** (K-1))

        K -= 1

        if K == 0:

            ans += 1

            break



print(ans)
import numpy as np



N = eval(input())

K = int(eval(input()))



n = len(N)

dp0 = np.zeros((n, K+1), np.int64)

dp1 = np.zeros((n, K+1), np.int64)



dp0[0, 0] = 1

dp0[0, 1] = int(N[0]) - 1

dp1[0, 1] = 1

for i, d in enumerate(N[1:]):

    dp0[i+1] += dp0[i]

    dp0[i+1, 1:] += dp0[i, :-1] * 9

    if int(d) == 0:

        dp1[i+1] = dp1[i]

    elif int(d) == 1:

        dp0[i+1] += dp1[i]

        dp1[i+1, 1:] = dp1[i, :-1]

    elif int(d) >= 2:

        dp0[i+1] += dp1[i]

        dp0[i+1, 1:] += dp1[i, :-1] * (int(d) - 1)

        dp1[i+1, 1:] = dp1[i, :-1]



print((dp0[-1, K] + dp1[-1, K]))

import numpy as np

N = eval(input())
K = int(eval(input()))
dp = np.zeros((len(N) + 1, K + 1), np.int64)
dp[1, 1] = 1
for d in range(1, len(N)):
    dp[d + 1] = dp[d]
    dp[d + 1, 1:] += dp[d, :-1]
ans = 0
for i, c in enumerate(N):
    n = len(N) - i
    if c != "0":
        ans += np.sum(dp[:n, K]) * (9**K)
        ans += dp[n, K] * (int(c) - 1) * (9 ** (K - 1))
        K -= 1
        if K == 0:
            ans += 1
            break
print(ans)

import numpy as np

N = eval(input())
K = int(eval(input()))
n = len(N)
dp0 = np.zeros((n, K + 1), np.int64)
dp1 = np.zeros((n, K + 1), np.int64)
dp0[0, 0] = 1
dp0[0, 1] = int(N[0]) - 1
dp1[0, 1] = 1
for i, d in enumerate(N[1:]):
    dp0[i + 1] += dp0[i]
    dp0[i + 1, 1:] += dp0[i, :-1] * 9
    if int(d) == 0:
        dp1[i + 1] = dp1[i]
    elif int(d) == 1:
        dp0[i + 1] += dp1[i]
        dp1[i + 1, 1:] = dp1[i, :-1]
    elif int(d) >= 2:
        dp0[i + 1] += dp1[i]
        dp0[i + 1, 1:] += dp1[i, :-1] * (int(d) - 1)
        dp1[i + 1, 1:] = dp1[i, :-1]
print((dp0[-1, K] + dp1[-1, K]))

-dp = np.zeros((len(N) + 1, K + 1), np.int64) -dp[1, 1] = 1 -for d in range(1, len(N)): -    dp[d + 1] = dp[d] -    dp[d + 1, 1:] += dp[d, :-1] -ans = 0 -for i, c in enumerate(N): -    n = len(N) - i -    if c != "0": -        ans += np.sum(dp[:n, K]) * (9**K) -        ans += dp[n, K] * (int(c) - 1) * (9 ** (K - 1)) -        K -= 1 -        if K == 0: -            ans += 1 -            break -print(ans) +n = len(N) +dp0 = np.zeros((n, K + 1), np.int64) +dp1 = np.zeros((n, K + 1), np.int64) +dp0[0, 0] = 1 +dp0[0, 1] = int(N[0]) - 1 +dp1[0, 1] = 1 +for i, d in enumerate(N[1:]): +    dp0[i + 1] += dp0[i] +    dp0[i + 1, 1:] += dp0[i, :-1] * 9 +    if int(d) == 0: +        dp1[i + 1] = dp1[i] +    elif int(d) == 1: +        dp0[i + 1] += dp1[i] +        dp1[i + 1, 1:] = dp1[i, :-1] +    elif int(d) >= 2: +        dp0[i + 1] += dp1[i] +        dp0[i + 1, 1:] += dp1[i, :-1] * (int(d) - 1) +        dp1[i + 1, 1:] = dp1[i, :-1] +print((dp0[-1, K] + dp1[-1, K]))