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

import math

def func(n,k):
  if k==0:
    return 0
  digit = len(n)
  res = 0
  if digit == 1:
    if k ==1:
      res = int(n)
    return res
  if digit == 2:
    if k ==2:
      res = (int(n) - 9 - int(n) //10)
    elif k == 3:
      res = (0)
    else:
      res = (9+int(n)//10)
    return res

  base = 9**k * (math.factorial(digit-1)/ (math.factorial(k) * math.factorial(digit-1-k)) )

  for i in range(9):
    i+= 1
    if i < int(n[0]):
      base += func(n[1:],k-1)
  return base

print(int(func(n,k)))