N = input()
K = int(input())
def Anger(n, k):
  d = int(n[0])
  if k == 1:
    S = d + 9 * (len(n) - 1)
    return S
  else:
    S = (d - 1) * (9 ** (k-1))
    for j in range(k-1):
      S *= len(n) - j - 1
      S //= j + 1
    T = 9 ** k
    for j in range(k):
      T *= len(n) - j - 1
      T //= j + 1
    return S + T + Anger(n[1:], k - 1)
    
print(Anger(N, K))