from math import factorial
N=int(input())
K=int(input())
#N,K = int(314159),int(3)
S = list(map(int,str(N)))
ans = 0
k = K
l = len(S)

def C(n,r):
    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0

def D(i,j): 
    return (9**j)*C(i,j)

for i in range(l):
    if k >= 1:
        #print('K:',k,',l:',l)
        #print((int(S[i])-1)*D(l-1,k-1)) #exa 3の時は1と2
        #print(D(l-1,k)) #S[0]==0の時の計算
        ans = ans + (int(S[i])-1)*D(l-1,k-1) + D(l-1,k)
        k -= 1
        l -= 1
    else:
        #ans += 1
        break

#print(K,len(S))
if K <= len(S):
    ans += 1

print(ans)

#https://atcoder.jp/contests/abc154/submissions/10100329