import numpy as np

N=int(input())
n=[int(i) for i in str(N)]
K=int(input())
L=len(n)
dp=np.zeros((L+1,2,K+1),dtype=int)
dp[0,0,0]=1

for i in range(L):
  for smaller in [0,1]:
    for j in range(0,K):
      m=10 if smaller else n[i]+1
      for x in range(m):
        if ( (j+(x!=0)) <= K )
          #i桁目がxだったときにdp[i][smaller][j]をどこに足しますか？
          dp[i+1][smaller or x<n[i]][j+(x!=0)]+=dp[i][smaller][j]
        
print(dp[L,:,K].sum())
