def calc(a,D,K):
  if K==1:
    return a+(D-1)*9
  elif K==2:
    return (a-1)*(D-1)*9 + (D-1)*(D-2)/2*81
  else:
    return (a-1)*(D-1)*(D-2)/2*81 + (D-1)*(D-2)*(D-3)/6*729

N=str(input())
K=int(input())
D = len(N)
score=0
for i,a in enumerate(N):
  if D-i>=K:
  	score+=calc(int(a),D-i,K)
  if a!="0":
    K-=1
  if K==0:
    break
print(int(score))