import itertools



N = eval(input())

K = int(eval(input()))

lN = len(N)



if K == 1:

    ans = int(N[0])+9*(lN-1)

    print(ans)



elif K == 2:

    not0 = 1000

    for i in range(1,lN):

        if int(N[i]) != 0:

            not0 = i

            break

    ans = 0

    n = [i for i in range(lN)]

    for v in itertools.combinations(n,2):

        if v[0] != 0:

            ans += 9*9

        else:

            if not0 >= v[1]:

                ans += (int(N[0])-1)*9 + int(N[v[1]])

            else:

                ans += int(N[0])*9

    print(ans)



else:

    not0f = 1000

    not0s = 1000

    for i in range(1,lN):

        if int(N[i]) != 0:

            not0f = i

            break

    for i in range(not0f+1,lN):

        if int(N[i]) != 0:

            not0s = i

            break

    ans = 0

    n = [i for i in range(lN)]

    for v in itertools.combinations(n,3):

        if v[0] != 0:

            ans += 9*9*9

        else:

            if not0f == v[1]:

                if not0s >= v[2]:

                    ans += (int(N[0])-1)*9*9

                    ans += (int(N[v[1]])-1)*9

                    ans += int(N[v[2]])

                else:

                    ans += (int(N[0])-1)*9*9

                    ans += int(N[v[1]])*9

            elif not0f < v[1]:

                ans += int(N[0])*9*9

            else:

                ans += (int(N[0])-1)*9*9

    print(ans)

N = int(eval(input()))

K = int(eval(input()))

S = str(N)

'''

ans = 0

li = []

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

    if str(i).count('0') == len(str(i)) - K:

        ans += 1

        li.append(i)

print(ans)

print(li)

'''

L = len(S)



dp = [[[1, 0], [0, 0], [0, 0], [0, 0]] for i in range(L)]

dp[0] = [[1, 0], [int(S[0])-1, 1], [0, 0], [0, 0]]

#print(dp)

for l in range(1,L):

    s = int(S[l])

    if s == 0:

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

        dp[l][2][1] += dp[l-1][2][1]

    else:

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

        dp[l][2][1] += dp[l-1][1][1]

        dp[l][3][1] += dp[l-1][2][1]

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

        dp[l][2][0] += dp[l-1][2][1]

        dp[l][3][0] += dp[l-1][3][1]



    dp[l][1][0] += dp[l-1][0][0]*9 + dp[l-1][1][0]

    dp[l][2][0] += dp[l-1][1][0]*9 + dp[l-1][2][0]

    dp[l][3][0] += dp[l-1][2][0]*9 + dp[l-1][3][0]

    dp[l][1][0] += dp[l-1][0][1]*max(0,s-1)

    dp[l][2][0] += dp[l-1][1][1]*max(0,s-1)

    dp[l][3][0] += dp[l-1][2][1]*max(0,s-1)



#print(dp)

print((sum(dp[L-1][K])))
import itertools

N = eval(input())
K = int(eval(input()))
lN = len(N)
if K == 1:
    ans = int(N[0]) + 9 * (lN - 1)
    print(ans)
elif K == 2:
    not0 = 1000
    for i in range(1, lN):
        if int(N[i]) != 0:
            not0 = i
            break
    ans = 0
    n = [i for i in range(lN)]
    for v in itertools.combinations(n, 2):
        if v[0] != 0:
            ans += 9 * 9
        else:
            if not0 >= v[1]:
                ans += (int(N[0]) - 1) * 9 + int(N[v[1]])
            else:
                ans += int(N[0]) * 9
    print(ans)
else:
    not0f = 1000
    not0s = 1000
    for i in range(1, lN):
        if int(N[i]) != 0:
            not0f = i
            break
    for i in range(not0f + 1, lN):
        if int(N[i]) != 0:
            not0s = i
            break
    ans = 0
    n = [i for i in range(lN)]
    for v in itertools.combinations(n, 3):
        if v[0] != 0:
            ans += 9 * 9 * 9
        else:
            if not0f == v[1]:
                if not0s >= v[2]:
                    ans += (int(N[0]) - 1) * 9 * 9
                    ans += (int(N[v[1]]) - 1) * 9
                    ans += int(N[v[2]])
                else:
                    ans += (int(N[0]) - 1) * 9 * 9
                    ans += int(N[v[1]]) * 9
            elif not0f < v[1]:
                ans += int(N[0]) * 9 * 9
            else:
                ans += (int(N[0]) - 1) * 9 * 9
    print(ans)

N = int(eval(input()))
K = int(eval(input()))
S = str(N)
"""
ans = 0
li = []
for i in range(1,N+1):
    if str(i).count('0') == len(str(i)) - K:
        ans += 1
        li.append(i)
print(ans)
print(li)
"""
L = len(S)
dp = [[[1, 0], [0, 0], [0, 0], [0, 0]] for i in range(L)]
dp[0] = [[1, 0], [int(S[0]) - 1, 1], [0, 0], [0, 0]]
# print(dp)
for l in range(1, L):
    s = int(S[l])
    if s == 0:
        dp[l][1][1] += dp[l - 1][1][1]
        dp[l][2][1] += dp[l - 1][2][1]
    else:
        dp[l][1][1] += dp[l - 1][0][1]
        dp[l][2][1] += dp[l - 1][1][1]
        dp[l][3][1] += dp[l - 1][2][1]
        dp[l][1][0] += dp[l - 1][1][1]
        dp[l][2][0] += dp[l - 1][2][1]
        dp[l][3][0] += dp[l - 1][3][1]
    dp[l][1][0] += dp[l - 1][0][0] * 9 + dp[l - 1][1][0]
    dp[l][2][0] += dp[l - 1][1][0] * 9 + dp[l - 1][2][0]
    dp[l][3][0] += dp[l - 1][2][0] * 9 + dp[l - 1][3][0]
    dp[l][1][0] += dp[l - 1][0][1] * max(0, s - 1)
    dp[l][2][0] += dp[l - 1][1][1] * max(0, s - 1)
    dp[l][3][0] += dp[l - 1][2][1] * max(0, s - 1)
# print(dp)
print((sum(dp[L - 1][K])))

-import itertools - -N = eval(input()) +N = int(eval(input())) -lN = len(N) -if K == 1: -    ans = int(N[0]) + 9 * (lN - 1) -    print(ans) -elif K == 2: -    not0 = 1000 -    for i in range(1, lN): -        if int(N[i]) != 0: -            not0 = i -            break -    ans = 0 -    n = [i for i in range(lN)] -    for v in itertools.combinations(n, 2): -        if v[0] != 0: -            ans += 9 * 9 -        else: -            if not0 >= v[1]: -                ans += (int(N[0]) - 1) * 9 + int(N[v[1]]) -            else: -                ans += int(N[0]) * 9 -    print(ans) -else: -    not0f = 1000 -    not0s = 1000 -    for i in range(1, lN): -        if int(N[i]) != 0: -            not0f = i -            break -    for i in range(not0f + 1, lN): -        if int(N[i]) != 0: -            not0s = i -            break -    ans = 0 -    n = [i for i in range(lN)] -    for v in itertools.combinations(n, 3): -        if v[0] != 0: -            ans += 9 * 9 * 9 -        else: -            if not0f == v[1]: -                if not0s >= v[2]: -                    ans += (int(N[0]) - 1) * 9 * 9 -                    ans += (int(N[v[1]]) - 1) * 9 -                    ans += int(N[v[2]]) -                else: -                    ans += (int(N[0]) - 1) * 9 * 9 -                    ans += int(N[v[1]]) * 9 -            elif not0f < v[1]: -                ans += int(N[0]) * 9 * 9 -            else: -                ans += (int(N[0]) - 1) * 9 * 9 -    print(ans) +S = str(N) +""" +ans = 0 +li = [] +for i in range(1,N+1): +    if str(i).count('0') == len(str(i)) - K: +        ans += 1 +        li.append(i) +print(ans) +print(li) +""" +L = len(S) +dp = [[[1, 0], [0, 0], [0, 0], [0, 0]] for i in range(L)] +dp[0] = [[1, 0], [int(S[0]) - 1, 1], [0, 0], [0, 0]] +# print(dp) +for l in range(1, L): +    s = int(S[l]) +    if s == 0: +        dp[l][1][1] += dp[l - 1][1][1] +        dp[l][2][1] += dp[l - 1][2][1] +    else: +        dp[l][1][1] += dp[l - 1][0][1] +        dp[l][2][1] += dp[l - 1][1][1] +        dp[l][3][1] += dp[l - 1][2][1] +        dp[l][1][0] += dp[l - 1][1][1] +        dp[l][2][0] += dp[l - 1][2][1] +        dp[l][3][0] += dp[l - 1][3][1] +    dp[l][1][0] += dp[l - 1][0][0] * 9 + dp[l - 1][1][0] +    dp[l][2][0] += dp[l - 1][1][0] * 9 + dp[l - 1][2][0] +    dp[l][3][0] += dp[l - 1][2][0] * 9 + dp[l - 1][3][0] +    dp[l][1][0] += dp[l - 1][0][1] * max(0, s - 1) +    dp[l][2][0] += dp[l - 1][1][1] * max(0, s - 1) +    dp[l][3][0] += dp[l - 1][2][1] * max(0, s - 1) +# print(dp) +print((sum(dp[L - 1][K])))