# 314159, 2,
# 0[xxxxx] 5C2 * 9*9 = 810
# 1[xxxxx] 5C1 * 9 = 45
# 2[xxxxx] 5C1 * 9 = 45
# 3[xxxxx] わからん!
# 31[0000] = 1
# 30[xxxx] = 4C1 * 9 合わせて937

# 9999, 3,
# 0[xxx] 3C3 * 9*9*9 = 729
# [yxxx] y=8, x=3C2 * 9*9 = 8 * 243
# 9[xxx] = 3C2 * 9*9 = 243

# 94599, 3,
# 0[xxxx] 4C3 * 9*9*9 = 4 * 729
# 1[xxxx] x=4C2 * 9*9 = 6 * 81
# ...
# 8[xxxx] x=4C2 * 9*9 = 6 * 81
# 94[x]00 = 5
# 940[xx] 2C1 * 9
# 93[xxx] 3C1 * 9
str_n = input()
n = int(str_n)
k = int(input())

if k > len(str_n):
  print(0)
  exit()

head = n
while head >= 10:
  head //= 10
def choice(p, q):
  if p == q:
    return 1
  res = 1
  for i in range(q):
    res = (res * p)
    p -= 1
  for i in range(q):
    res = res // (i+1)
  return res

ans = choice(len(str_n)-1, k) * (9 ** k)
for i in range(1, head):
  ans += choice(len(str_n)-1, k-1) * (9 ** (k-1))
if k == 3:
  ans += int(str_n[2])  # 99x0000
  ans += choice(len(str_n) - 3, 1) * 9  # 990xxx
  ans += (int(str_n[1])-1) * choice(len(str_n) - 2, 1) * 9  # 9[1:8]xxxx
  ans += choice(len(str_n) - 2, 2) * 9*9  # 90xxxxx
if k == 2:
  ans += int(str_n[1])
  ans += choice(len(str_n) - 2, 1) * 9
if k == 1:
  ans += int(str_n[0])

print(ans)
