N = int(input())
K = int(input())
n = len(str(N))
ans = 0

def com(n,k):
  a = n
  b = k
  for i in range(K-2):
    a = a*(n-(i+1))
    b = b*(k-(i+1))
  return a//b

def count(n,K):
  if n < K:
    return 0
  elif n == K:
    return 9**K
  elif n > K and K == 1:
    return 9
  elif n > K and K != 1:
    a = n-1
    b = K-1
    for i in range(K-2):
      a = a*(n-1-(i+1))
    for j in range(K-2):
      b = b*(K-1-(j+1))
    C = a//b
    return C*(9**K)

for i in range(n-1):
  ans += count(i+1,K)

M = str(N)
s,t,u = int(M[0]),int(M[1]),int(M[2])
if K == 1:
  ans += s
elif K == 2:
  ans = ans + (s-1)*(9*(n-1)) + 9*(n-2) + t
elif K == 3:
  ans = ans + (s-1)*(9**2)*com(n-1,K-1) + (9**(K-1))*com(n-2,K-1) + (t-1)*9*(n-2) + 9*(n-3) + u

print(ans)