#500
N = int(input())
K = int(input())
string = str(N)
digit = len(string)
dp = [[[0,0] for _ in range(K+1)] for _ in range(digit+1)]

dp[0][0][0] = 1
dp[0][0][1] = 0

for i in range(digit):
    for j in range(K):
        dp[i+1][0][1] = 1
        dp[i+1][j+1][0] += dp[i][j][0]
        if string[i] == "0":
            dp[i+1][j+1][0] += dp[i][j+1][0]
        dp[i+1][j+1][1] += 9*dp[i][j][1] + dp[i][j+1][1]
        if string[i] != "0":
            dp[i+1][j+1][1] += dp[i][j+1][0] + (int(string[i])-1)*dp[i][j][0]
            
if N - 10*(digit-1) and K >= 2:
    n = dp[digit][K][1]
else:
    n = dp[digit][K][0] + dp[digit][K][1]
print(n)