n = input()
k = int(input())

mainDigit = len(n)

def digitOne(digit, p):
  return 9 * (digit - 1) + p

def digitTwo(digit, p, q, qZure):
  return 81 * (digit-1) * (digit-2) // 2 + 9 * (digit-1) * (p-1) + digitOne(digit-1-qZure, q)

if k == 1:
  print(digitOne(mainDigit, int(n[0])))
elif k == 2:
  qZure = 0
  for i in range(1, mainDigit):
    if int(n[i]) == 0:
      qZure += 1
    else:
      break
  print(digitTwo(mainDigit, int(n[0]), int(n[qZure+1]), qZure))
