from itertools import combinations as com

def comb(a,b):

  if a == 0:

    return 1

  r = 1

  for i in range(b):

    r *= a

    a -= 1

  r = r // [1,2,6][b-1]

  return r

n = eval(input())

nl = len(n)

k = int(eval(input()))

i = 0

c = 0

while i < nl:

  if i+1 >= nl:

    break

  if i+1 < k:

    pass

  else:

    if k == 1:

      c += 9

    elif k == 2:

      c += 81 * i

    else:

      c += 729 * (i*(i-1))//2

  i += 1

lis = []

if k == 1:

  for cur in range(1,10):

    cur = cur * 10**i

    lis.append(cur)

elif k == 2:

  for j in range(i):

    for k in range(1,10):

      for cur in range(1,10):

        cur = cur * 10**i + k * 10**j

        lis.append(cur)

else:

  for j,k in com(list(range(i)),2):

    for l in range(1,10):

      for m in range(1,10):

        for cur in range(1,10):

          if cur < int(n[0]):

            c += 1

          else:

            cur = str(cur) + '0'*(i-k-1) + str(l) + '0'*(k-j-1) + str(m) + '0'*j

            if cur <= n:

              c += 1

n = int(n)

for i in lis:

  if i <= n:

    c += 1

print(c)
n = eval(input())

k = int(eval(input()))

dp0 = [0] * 4

dp1 = [1,0,0,0]

for i in n:

  i = int(i)

  pdp0,pdp1,dp0 = dp0,dp1,[0]*4

  if i != 0:

    dp1 = [0] + pdp1[:-1]

  else:

    dp1 = pdp1

  dp0[0] = pdp0[0]+(i!=0)*pdp1[0]

  for j in range(1,4):

    dp0[j] = 9*pdp0[j-1] + pdp0[j] + (i!=0)*(i-1)*pdp1[j-1] + (i!=0)*pdp1[j]

print((dp0[k]+dp1[k]))
from itertools import combinations as com


def comb(a, b):
    if a == 0:
        return 1
    r = 1
    for i in range(b):
        r *= a
        a -= 1
    r = r // [1, 2, 6][b - 1]
    return r


n = eval(input())
nl = len(n)
k = int(eval(input()))
i = 0
c = 0
while i < nl:
    if i + 1 >= nl:
        break
    if i + 1 < k:
        pass
    else:
        if k == 1:
            c += 9
        elif k == 2:
            c += 81 * i
        else:
            c += 729 * (i * (i - 1)) // 2
    i += 1
lis = []
if k == 1:
    for cur in range(1, 10):
        cur = cur * 10**i
        lis.append(cur)
elif k == 2:
    for j in range(i):
        for k in range(1, 10):
            for cur in range(1, 10):
                cur = cur * 10**i + k * 10**j
                lis.append(cur)
else:
    for j, k in com(list(range(i)), 2):
        for l in range(1, 10):
            for m in range(1, 10):
                for cur in range(1, 10):
                    if cur < int(n[0]):
                        c += 1
                    else:
                        cur = (
                            str(cur)
                            + "0" * (i - k - 1)
                            + str(l)
                            + "0" * (k - j - 1)
                            + str(m)
                            + "0" * j
                        )
                        if cur <= n:
                            c += 1
n = int(n)
for i in lis:
    if i <= n:
        c += 1
print(c)

n = eval(input())
k = int(eval(input()))
dp0 = [0] * 4
dp1 = [1, 0, 0, 0]
for i in n:
    i = int(i)
    pdp0, pdp1, dp0 = dp0, dp1, [0] * 4
    if i != 0:
        dp1 = [0] + pdp1[:-1]
    else:
        dp1 = pdp1
    dp0[0] = pdp0[0] + (i != 0) * pdp1[0]
    for j in range(1, 4):
        dp0[j] = (
            9 * pdp0[j - 1]
            + pdp0[j]
            + (i != 0) * (i - 1) * pdp1[j - 1]
            + (i != 0) * pdp1[j]
        )
print((dp0[k] + dp1[k]))

-from itertools import combinations as com - - -def comb(a, b): -    if a == 0: -        return 1 -    r = 1 -    for i in range(b): -        r *= a -        a -= 1 -    r = r // [1, 2, 6][b - 1] -    return r - - -nl = len(n) -i = 0 -c = 0 -while i < nl: -    if i + 1 >= nl: -        break -    if i + 1 < k: -        pass +dp0 = [0] * 4 +dp1 = [1, 0, 0, 0] +for i in n: +    i = int(i) +    pdp0, pdp1, dp0 = dp0, dp1, [0] * 4 +    if i != 0: +        dp1 = [0] + pdp1[:-1] -        if k == 1: -            c += 9 -        elif k == 2: -            c += 81 * i -        else: -            c += 729 * (i * (i - 1)) // 2 -    i += 1 -lis = [] -if k == 1: -    for cur in range(1, 10): -        cur = cur * 10**i -        lis.append(cur) -elif k == 2: -    for j in range(i): -        for k in range(1, 10): -            for cur in range(1, 10): -                cur = cur * 10**i + k * 10**j -                lis.append(cur) -else: -    for j, k in com(list(range(i)), 2): -        for l in range(1, 10): -            for m in range(1, 10): -                for cur in range(1, 10): -                    if cur < int(n[0]): -                        c += 1 -                    else: -                        cur = ( -                            str(cur) -                            + "0" * (i - k - 1) -                            + str(l) -                            + "0" * (k - j - 1) -                            + str(m) -                            + "0" * j -                        ) -                        if cur <= n: -                            c += 1 -n = int(n) -for i in lis: -    if i <= n: -        c += 1 -print(c) +        dp1 = pdp1 +    dp0[0] = pdp0[0] + (i != 0) * pdp1[0] +    for j in range(1, 4): +        dp0[j] = ( +            9 * pdp0[j - 1] +            + pdp0[j] +            + (i != 0) * (i - 1) * pdp1[j - 1] +            + (i != 0) * pdp1[j] +        ) +print((dp0[k] + dp1[k]))