n=input()
k=int(input())
m=len(n)

DP=[[[0]*(k+1) for _ in range(2)] for _ in range(m+1)]
DP[0][0][0]=1

for i in range(1,m+1):
    for flag in range(2):
        num=9 if flag else int(n[i-1])
        for j in range(k+1):
            for k in range(num+1):
                if k!=0:
                    DP[i][flag or k<=num][j] +=DP[i-1][flag][j-1]
                else:
                    DP[i][flag or k<=num][j] +=DP[i-1][flag][j]
print(DP[-1][0][k]+DP[-1][1][k])