import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

def fact_fun(n):
  if n == 0:
    return 1
  fact_num=int(1) 
  for i in range(1,n+1):
      fact_num=i*fact_num
  return fact_num

def c_n_x(case_count,real_count):
  fact_n = fact_fun(case_count)
  fact_x = fact_fun(real_count)
  fact_n_x = fact_fun(case_count - real_count)
  c_n_x_num = fact_n // (fact_x*fact_n_x)
  return c_n_x_num
def f(k):
    res=int(9)
    for i in range(1,k):
        res*=9
    return res

s = input()
l=len(s)
ans=int(0)
k=int(input())
for i in range(1,l):
    if k>i:continue
    num=i-k
    #print(str(i-1)+" "+str(k-1)+" "+str(c_n_x(i-1,k-1)*f(k)))
    ans+=c_n_x(i-1,k-1)*f(k)
#print(ans)
res=1
if k==1:
    ans+=int(s[0])
if k==2:
    flag=int(0)
    for i in range(1,l):
        
        ans+=(int(s[0])-1)*9+max((int(s[i])),flag)
        if int(s[i])>0:flag=9
if k==3:
    num1=int(0)
    num2=int(0)
    for i in range(1,l):
        num2=0
        for j in range(i+1,l):
            ans+=(int(s[0])-1)*9*9
            if num1==9:ans+=9*9
            else:ans+=(int(s[i])-1)*9+max(num1,1)*max(int(s[j]),num2)
            if int(s[j])>0:num2=9
        if int(s[i])>0:num1=9
       
print(ans)


