import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n=int(input())
k=int(input())

l=n
l=str(l)
keta=len(l)
num=[0 for i in range(keta)]
ans=0
m=n
for i in range(keta):
  num[i]=m%10
  m//=10
#print(num)
if k==1:
  ans+=num[-1]+(keta-1)*9
if k==2:
  ans+=(num[-1]-1)*(keta-1)*9
  for i in range(keta-1):
    if i!=keta-2:
      ans+=9
    else:
      ans+=num[i]
  if keta>=3:
    ans+=comb(keta-1,2)*81
if k==3:
  ans+=comb(keta-1,3)*729
  ans+=(num[-1]-1)*comb(keta-1,2)*81
  ans+=(num[-2]-1)*(keta-2)*9
  for i in range(keta-2):
    ans+=num[i]
print(ans)
