N=int(input())
K=int(input())

c=len(str(N))
a=[[0 for _ in range(5)] for _ in range(c+1)]
a[0][0],a[1][0],a[1][1]=1,1,9

def dfs(n,k,o):
  d=n//10**(o-1)
  if d==0:
    return a[o-2][k]+(dfs(n,k,o-1) if o>1 else 0)
  else:
    return a[o-1][k-1]*((d-1) if o>1 else d) +a[o-1][k]+ (dfs(n-d*10**(o-1),k-1,o-1) if (k>0 and o>1) else 0)

for i in range(2,c):
  for j in range(4):
    a[i][j]=a[i-1][j-1]*9+a[i-1][j]

print(dfs(N,K,c))
