from itertools import product
N=input()
K=int(input())

dp=[[[0 for _ in range(K+1)] for _ in range(2)] for _ in range(len(N)+1)]

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

for i in range(len(N)):
    for smaller in range(2):
        for j in range(K+1):
            for x in range(1 if j==K else int(N[i])+1 if smaller==0 else 10):
                dp[i+1][smaller or (x < int(N[i]))][j+x!=0]+=dp[i][smaller][j]
print(dp[len(N)][1][K]+dp[len(N)][0][K])
