

from functools import lru_cache



@lru_cache(maxsize=10000)

def calc(n, k):

    # print(n, k)



    if n < 10:

        if k > 1:

            # print('1:return 0')

            return 0

        elif k == 1:

            # print('2:return ' + str(n))

            return n

        else:

            return 1



    else:

        if k == 0:

            # print('5:return ')

            return 1#calc(n // 10, k)

        else:

            # print('6:return ')

            return calc(n // 10, k - 1) * (n % 10) + calc(n // 10 - 1, k - 1) * (9 - n % 10) + calc(n // 10, k)



n = int(eval(input()))

k = int(eval(input()))



print((calc(n, k)))

n = eval(input())

K = int(eval(input()))

L = len(n)



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

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



for i in range(L):

    d = int(n[i])

    for j in [0, 1]:

        for k in range(K + 1):

            if j == 0:

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

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

            else:

                if d > 0:

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

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

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

                else:

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





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



from functools import lru_cache


@lru_cache(maxsize=10000)
def calc(n, k):
    # print(n, k)
    if n < 10:
        if k > 1:
            # print('1:return 0')
            return 0
        elif k == 1:
            # print('2:return ' + str(n))
            return n
        else:
            return 1
    else:
        if k == 0:
            # print('5:return ')
            return 1  # calc(n // 10, k)
        else:
            # print('6:return ')
            return (
                calc(n // 10, k - 1) * (n % 10)
                + calc(n // 10 - 1, k - 1) * (9 - n % 10)
                + calc(n // 10, k)
            )


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

n = eval(input())
K = int(eval(input()))
L = len(n)
dp = [[[0] * (K + 2) for _ in range(2)] for __ in range(L + 1)]
dp[0][1][0] = 1
for i in range(L):
    d = int(n[i])
    for j in [0, 1]:
        for k in range(K + 1):
            if j == 0:
                dp[i + 1][j][k] += dp[i][j][k]
                dp[i + 1][j][k + 1] += dp[i][j][k] * 9
            else:
                if d > 0:
                    dp[i + 1][0][k] += dp[i][j][k]
                    dp[i + 1][0][k + 1] += dp[i][j][k] * (d - 1)
                    dp[i + 1][1][k + 1] += dp[i][j][k]
                else:
                    dp[i + 1][1][k] += dp[i][j][k]
print((dp[L][0][K] + dp[L][1][K]))

-from functools import lru_cache - - -@lru_cache(maxsize=10000) -def calc(n, k): -    # print(n, k) -    if n < 10: -        if k > 1: -            # print('1:return 0') -            return 0 -        elif k == 1: -            # print('2:return ' + str(n)) -            return n -        else: -            return 1 -    else: -        if k == 0: -            # print('5:return ') -            return 1  # calc(n // 10, k) -        else: -            # print('6:return ') -            return ( -                calc(n // 10, k - 1) * (n % 10) -                + calc(n // 10 - 1, k - 1) * (9 - n % 10) -                + calc(n // 10, k) -            ) - - -n = int(eval(input())) -k = int(eval(input())) -print((calc(n, k))) +n = eval(input()) +K = int(eval(input())) +L = len(n) +dp = [[[0] * (K + 2) for _ in range(2)] for __ in range(L + 1)] +dp[0][1][0] = 1 +for i in range(L): +    d = int(n[i]) +    for j in [0, 1]: +        for k in range(K + 1): +            if j == 0: +                dp[i + 1][j][k] += dp[i][j][k] +                dp[i + 1][j][k + 1] += dp[i][j][k] * 9 +            else: +                if d > 0: +                    dp[i + 1][0][k] += dp[i][j][k] +                    dp[i + 1][0][k + 1] += dp[i][j][k] * (d - 1) +                    dp[i + 1][1][k + 1] += dp[i][j][k] +                else: +                    dp[i + 1][1][k] += dp[i][j][k] +print((dp[L][0][K] + dp[L][1][K]))