from functools import lru_cache

N = int(eval(input()))

K = int(eval(input()))

@lru_cache(None)

def f(n,k):

  if k<0:

    return 0

  if n<10:

    if k>1:

      return 0

    elif k==1:

      return n

    elif k==0:

      return 1

  a, b = divmod(n,10)

  m = 9*f(a-1,k-1)+f(a,k)+b*(f(a,k-1)-f(a-1,k-1))

  return m

print((f(N,K)))
N = eval(input())

K = int(eval(input()))

L = len(N)

dp0 = [[0]*(K+1) for i in range(L+1)]

dp1 = [[0]*(K+1) for i in range(L+1)]

dp0[0][0] = 1

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

  c = int(N[i-1])

  for j in range(K+1):

    if j==0:

      if c>0:

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

        dp0[i][j] = 0

      else:

        dp1[i][j] = dp1[i-1][j]

        dp0[i][j] = dp0[i-1][j]

    else:

      if c>0:

        dp1[i][j] = dp0[i-1][j-1]*(c-1)+dp1[i-1][j-1]*9+dp1[i-1][j]+dp0[i-1][j]

        dp0[i][j] = dp0[i-1][j-1]

      else:

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

        dp0[i][j] = dp0[i-1][j]

print((dp0[-1][-1]+dp1[-1][-1]))
from functools import lru_cache

N = int(eval(input()))
K = int(eval(input()))


@lru_cache(None)
def f(n, k):
    if k < 0:
        return 0
    if n < 10:
        if k > 1:
            return 0
        elif k == 1:
            return n
        elif k == 0:
            return 1
    a, b = divmod(n, 10)
    m = 9 * f(a - 1, k - 1) + f(a, k) + b * (f(a, k - 1) - f(a - 1, k - 1))
    return m


print((f(N, K)))

N = eval(input())
K = int(eval(input()))
L = len(N)
dp0 = [[0] * (K + 1) for i in range(L + 1)]
dp1 = [[0] * (K + 1) for i in range(L + 1)]
dp0[0][0] = 1
for i in range(1, L + 1):
    c = int(N[i - 1])
    for j in range(K + 1):
        if j == 0:
            if c > 0:
                dp1[i][j] = dp1[i - 1][j] + dp0[i - 1][j]
                dp0[i][j] = 0
            else:
                dp1[i][j] = dp1[i - 1][j]
                dp0[i][j] = dp0[i - 1][j]
        else:
            if c > 0:
                dp1[i][j] = (
                    dp0[i - 1][j - 1] * (c - 1)
                    + dp1[i - 1][j - 1] * 9
                    + dp1[i - 1][j]
                    + dp0[i - 1][j]
                )
                dp0[i][j] = dp0[i - 1][j - 1]
            else:
                dp1[i][j] = dp1[i - 1][j - 1] * 9 + dp1[i - 1][j]
                dp0[i][j] = dp0[i - 1][j]
print((dp0[-1][-1] + dp1[-1][-1]))

-from functools import lru_cache - -N = int(eval(input())) +N = eval(input()) - - -@lru_cache(None) -def f(n, k): -    if k < 0: -        return 0 -    if n < 10: -        if k > 1: -            return 0 -        elif k == 1: -            return n -        elif k == 0: -            return 1 -    a, b = divmod(n, 10) -    m = 9 * f(a - 1, k - 1) + f(a, k) + b * (f(a, k - 1) - f(a - 1, k - 1)) -    return m - - -print((f(N, K))) +L = len(N) +dp0 = [[0] * (K + 1) for i in range(L + 1)] +dp1 = [[0] * (K + 1) for i in range(L + 1)] +dp0[0][0] = 1 +for i in range(1, L + 1): +    c = int(N[i - 1]) +    for j in range(K + 1): +        if j == 0: +            if c > 0: +                dp1[i][j] = dp1[i - 1][j] + dp0[i - 1][j] +                dp0[i][j] = 0 +            else: +                dp1[i][j] = dp1[i - 1][j] +                dp0[i][j] = dp0[i - 1][j] +        else: +            if c > 0: +                dp1[i][j] = ( +                    dp0[i - 1][j - 1] * (c - 1) +                    + dp1[i - 1][j - 1] * 9 +                    + dp1[i - 1][j] +                    + dp0[i - 1][j] +                ) +                dp0[i][j] = dp0[i - 1][j - 1] +            else: +                dp1[i][j] = dp1[i - 1][j - 1] * 9 + dp1[i - 1][j] +                dp0[i][j] = dp0[i - 1][j] +print((dp0[-1][-1] + dp1[-1][-1]))