n = int(eval(input()))

N = len(str(n))

k = int(eval(input()))

s = [int(i) for i in str(n)]

dpi = [[0]*(k+1) for _ in range(N+1)]

dpj = [[0]*(k+1) for _ in range(N+1)]

dpi[0][0] = 1

for i in range(N):

    for j in range(k+1):

        dpi[i+1][j] += dpi[i][j]*(s[i]==0)

        dpj[i+1][j] += dpj[i][j]+dpi[i][j]*(s[i]>0)

        if j < k:

            dpi[i+1][j+1]+=dpi[i][j]*(s[i]>0)

            dpj[i+1][j+1]+=dpj[i][j]*9+dpi[i][j]*max(0,s[i]-1)

print((dpi[N][k]+dpj[N][k]))
n = eval(input())

k = int(eval(input()))

dp0 = [[0]*(k+1) for _ in range(len(n)+1)]

dp1 = [[0]*(k+1) for _ in range(len(n)+1)]

dp0[0][0] = 1

for i in range(len(n)):

    for j in range(k+1):

        if int(n[i]) == 0:

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

        if int(n[i]) > 0:

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

            if j < k:

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

                dp1[i+1][j+1] += dp0[i][j]*(int(n[i])-1)

        if j < k:

            dp1[i+1][j+1] += dp1[i][j]*9

        dp1[i+1][j] += dp1[i][j]

print((dp0[len(n)][k]+dp1[len(n)][k]))
n = int(eval(input()))
N = len(str(n))
k = int(eval(input()))
s = [int(i) for i in str(n)]
dpi = [[0] * (k + 1) for _ in range(N + 1)]
dpj = [[0] * (k + 1) for _ in range(N + 1)]
dpi[0][0] = 1
for i in range(N):
    for j in range(k + 1):
        dpi[i + 1][j] += dpi[i][j] * (s[i] == 0)
        dpj[i + 1][j] += dpj[i][j] + dpi[i][j] * (s[i] > 0)
        if j < k:
            dpi[i + 1][j + 1] += dpi[i][j] * (s[i] > 0)
            dpj[i + 1][j + 1] += dpj[i][j] * 9 + dpi[i][j] * max(0, s[i] - 1)
print((dpi[N][k] + dpj[N][k]))

n = eval(input())
k = int(eval(input()))
dp0 = [[0] * (k + 1) for _ in range(len(n) + 1)]
dp1 = [[0] * (k + 1) for _ in range(len(n) + 1)]
dp0[0][0] = 1
for i in range(len(n)):
    for j in range(k + 1):
        if int(n[i]) == 0:
            dp0[i + 1][j] += dp0[i][j]
        if int(n[i]) > 0:
            dp1[i + 1][j] += dp0[i][j]
            if j < k:
                dp0[i + 1][j + 1] += dp0[i][j]
                dp1[i + 1][j + 1] += dp0[i][j] * (int(n[i]) - 1)
        if j < k:
            dp1[i + 1][j + 1] += dp1[i][j] * 9
        dp1[i + 1][j] += dp1[i][j]
print((dp0[len(n)][k] + dp1[len(n)][k]))

-n = int(eval(input())) -N = len(str(n)) +n = eval(input()) -s = [int(i) for i in str(n)] -dpi = [[0] * (k + 1) for _ in range(N + 1)] -dpj = [[0] * (k + 1) for _ in range(N + 1)] -dpi[0][0] = 1 -for i in range(N): +dp0 = [[0] * (k + 1) for _ in range(len(n) + 1)] +dp1 = [[0] * (k + 1) for _ in range(len(n) + 1)] +dp0[0][0] = 1 +for i in range(len(n)): -        dpi[i + 1][j] += dpi[i][j] * (s[i] == 0) -        dpj[i + 1][j] += dpj[i][j] + dpi[i][j] * (s[i] > 0) +        if int(n[i]) == 0: +            dp0[i + 1][j] += dp0[i][j] +        if int(n[i]) > 0: +            dp1[i + 1][j] += dp0[i][j] +            if j < k: +                dp0[i + 1][j + 1] += dp0[i][j] +                dp1[i + 1][j + 1] += dp0[i][j] * (int(n[i]) - 1) -            dpi[i + 1][j + 1] += dpi[i][j] * (s[i] > 0) -            dpj[i + 1][j + 1] += dpj[i][j] * 9 + dpi[i][j] * max(0, s[i] - 1) -print((dpi[N][k] + dpj[N][k])) +            dp1[i + 1][j + 1] += dp1[i][j] * 9 +        dp1[i + 1][j] += dp1[i][j] +print((dp0[len(n)][k] + dp1[len(n)][k]))