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

d = len(str(n))

dp = [[[0]*10 for i in range(4)] for j in range(110)]
dp[0][0][0] = 1
dp[1][0][0] = 1

for i in range(1, 110):
  for j in range(1, 4):
    for p in range(10):
      if p != 0:
        dp[i][j][p] = sum(dp[i-1][j-1])
      else:
        dp[i][j][p] = sum(dp[i-1][j]) 
      
#print(dp[0])
#print(dp[1])
#print(dp[2])
#print(dp[6])

n_ = str(n)
ans = 0

for i in range(d):
  a = d - i #桁
  b = int(n_[i])
  for x in range(b):
    ans += dp[a][max(k-i, 0)][x]
  #print(ans)
print(ans)