N = int(input())
K = int(input())

def f(n,k):
  if k == 1:
    if n < 10:
      return n
    else:
      r = n%10
      m = (n-r)/10
      return f(m,1) + 9
  else:
    if n < 10:
      return 0
    else:
      r = n%10
      m = (n-r)/10
      return f(m,k) + f(m,k-1) * r + f(m-1,k-1) * (9-r)
    
print(f(N,K))