n = list(map(int, list(input())))
k = int(input())

dp = [[0,0,0] for _ in range(len(n)+1)]
counter = 0
dp[0][0] = n[0]-1
for i in range(1, len(n)):
    dp[i][0] += dp[i-1][0] + 9
    dp[i][1] += dp[i-1][0]*9 + dp[i-1][1]
    dp[i][2] += dp[i-1][1]*9 + dp[i-1][2]
    counter += n[i]>0
    if counter < k and n[i] != 0:
        dp[i][counter] += n[i]-1
    if 0<counter and counter < k and n[i] != 0:
        dp[i][counter-1] += 1

print(dp[len(n)-1][k-1]+(counter<=k))