

import numpy as np



N=eval(input())

K=eval(input())

dp=np.zeros((len(str(N))+10,len(str(N))+10,2))

dp=dp.tolist()





x0=int(N[0])

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





for i in range(0,len(N),1):

    for j in range(0,4,1):

        for k in range(0,2,1):

            nd=int(N[i])

            for d in range(0,10,1):

                ni=i+1

                nj=j

                nk=k

                if not(d==0):

                    nj=nj+1

                if ((k==0)and(d<nd)):

                    nk=1

                if (not(nj>int(K)))and(not((k==0)and(d>nd))):

                    dp[ni][nj][nk]=dp[ni][nj][nk]+dp[i][j][k]





print((int(dp[len(N)][int(K)][0]+dp[len(N)][int(K)][1])))

N=list(eval(input()))

K=int(eval(input()))

N=list(map(int,N))

#print(N)

dp=[[[0 for _ in range(4)] for _ in range(len(N))] for _ in range(2)]

for i in range(len(N)):

    num=N[i]

    mayover=0

    if i==0:

        for j in range(10):

            if j<num:

                if j==0:

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

                else:

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

            elif j==num:

                if j==0:

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

                else:

                    dp[1][i][1] = dp[1][i][1] + 1

    else:



        for j in range(2):

            if j==0:

                for l in range(4):

                    dp[j][i][l] = dp[j][i][l] + dp[j][i - 1][l]

                    if l != 0:

                        dp[j][i][l] = dp[j][i][l] + 9*dp[j][i - 1][l - 1]

            else:

                if num==0:

                    for l in range(4):

                        dp[j][i][l]=dp[j][i-1][l]

                else:

                    for l in range(4):

                        dp[0][i][l]=dp[0][i][l]+dp[j][i-1][l]

                        if l!=0:

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

                            dp[1][i][l]=dp[1][i][l]+dp[j][i-1][l-1]



    #print(dp[0][i],dp[1][i])

    #input()

print((dp[0][len(N)-1][K]+dp[1][len(N)-1][K]))













import numpy as np

N = eval(input())
K = eval(input())
dp = np.zeros((len(str(N)) + 10, len(str(N)) + 10, 2))
dp = dp.tolist()
x0 = int(N[0])
dp[0][0][0] = 1
for i in range(0, len(N), 1):
    for j in range(0, 4, 1):
        for k in range(0, 2, 1):
            nd = int(N[i])
            for d in range(0, 10, 1):
                ni = i + 1
                nj = j
                nk = k
                if not (d == 0):
                    nj = nj + 1
                if (k == 0) and (d < nd):
                    nk = 1
                if (not (nj > int(K))) and (not ((k == 0) and (d > nd))):
                    dp[ni][nj][nk] = dp[ni][nj][nk] + dp[i][j][k]
print((int(dp[len(N)][int(K)][0] + dp[len(N)][int(K)][1])))

N = list(eval(input()))
K = int(eval(input()))
N = list(map(int, N))
# print(N)
dp = [[[0 for _ in range(4)] for _ in range(len(N))] for _ in range(2)]
for i in range(len(N)):
    num = N[i]
    mayover = 0
    if i == 0:
        for j in range(10):
            if j < num:
                if j == 0:
                    dp[0][i][0] = dp[0][i][0] + 1
                else:
                    dp[0][i][1] = dp[0][i][1] + 1
            elif j == num:
                if j == 0:
                    dp[1][i][0] = dp[1][i][0] + 1
                else:
                    dp[1][i][1] = dp[1][i][1] + 1
    else:
        for j in range(2):
            if j == 0:
                for l in range(4):
                    dp[j][i][l] = dp[j][i][l] + dp[j][i - 1][l]
                    if l != 0:
                        dp[j][i][l] = dp[j][i][l] + 9 * dp[j][i - 1][l - 1]
            else:
                if num == 0:
                    for l in range(4):
                        dp[j][i][l] = dp[j][i - 1][l]
                else:
                    for l in range(4):
                        dp[0][i][l] = dp[0][i][l] + dp[j][i - 1][l]
                        if l != 0:
                            dp[0][i][l] = dp[0][i][l] + (num - 1) * dp[j][i - 1][l - 1]
                            dp[1][i][l] = dp[1][i][l] + dp[j][i - 1][l - 1]
    # print(dp[0][i],dp[1][i])
    # input()
print((dp[0][len(N) - 1][K] + dp[1][len(N) - 1][K]))

-import numpy as np - -N = eval(input()) -K = eval(input()) -dp = np.zeros((len(str(N)) + 10, len(str(N)) + 10, 2)) -dp = dp.tolist() -x0 = int(N[0]) -dp[0][0][0] = 1 -for i in range(0, len(N), 1): -    for j in range(0, 4, 1): -        for k in range(0, 2, 1): -            nd = int(N[i]) -            for d in range(0, 10, 1): -                ni = i + 1 -                nj = j -                nk = k -                if not (d == 0): -                    nj = nj + 1 -                if (k == 0) and (d < nd): -                    nk = 1 -                if (not (nj > int(K))) and (not ((k == 0) and (d > nd))): -                    dp[ni][nj][nk] = dp[ni][nj][nk] + dp[i][j][k] -print((int(dp[len(N)][int(K)][0] + dp[len(N)][int(K)][1]))) +N = list(eval(input())) +K = int(eval(input())) +N = list(map(int, N)) +# print(N) +dp = [[[0 for _ in range(4)] for _ in range(len(N))] for _ in range(2)] +for i in range(len(N)): +    num = N[i] +    mayover = 0 +    if i == 0: +        for j in range(10): +            if j < num: +                if j == 0: +                    dp[0][i][0] = dp[0][i][0] + 1 +                else: +                    dp[0][i][1] = dp[0][i][1] + 1 +            elif j == num: +                if j == 0: +                    dp[1][i][0] = dp[1][i][0] + 1 +                else: +                    dp[1][i][1] = dp[1][i][1] + 1 +    else: +        for j in range(2): +            if j == 0: +                for l in range(4): +                    dp[j][i][l] = dp[j][i][l] + dp[j][i - 1][l] +                    if l != 0: +                        dp[j][i][l] = dp[j][i][l] + 9 * dp[j][i - 1][l - 1] +            else: +                if num == 0: +                    for l in range(4): +                        dp[j][i][l] = dp[j][i - 1][l] +                else: +                    for l in range(4): +                        dp[0][i][l] = dp[0][i][l] + dp[j][i - 1][l] +                        if l != 0: +                            dp[0][i][l] = dp[0][i][l] + (num - 1) * dp[j][i - 1][l - 1] +                            dp[1][i][l] = dp[1][i][l] + dp[j][i - 1][l - 1] +    # print(dp[0][i],dp[1][i]) +    # input() +print((dp[0][len(N) - 1][K] + dp[1][len(N) - 1][K]))