N = int(input())
K = int(input())
count = 0

if K == 1:
  N = str(N)
  keta = len(N)
  str_keta = str(keta)
  count += int(N[0])
  count += (len(N)-1)*9
else:
  for i in range(N+1):
    if i == 0:
      pass
    else:
      i = str(i)
      i = i.replace("0", "")
      len_i = len(i)
      if len_i == K:
        count += 1
        
print(count)