import math

N=int(input())
K=int(input())
d = len(str(N)) #桁数

#nCr組み合わせ
def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N<9999:
    answer=0
    for i in range(N):
        if (d- str(i).zfill(d).count('0'))==K:
            answer+=1
    print(answer)
elif d > K:
    max_d_val= int(str(N)[-d])
    max_d_val_2= int(str(N)[-(d-1)])
    max_d_val_3 = int(str(N)[-(d-2)])
    if K==1:
        answer = combinations_count(d,K)*(9**K)- combinations_count(d-1,K-1)*(9**(K-1))*(9-max_d_val)
        print(answer)
    if K==2:
        mother = combinations_count(d,K)*(9**K)
        f1 = combinations_count(d-1,K-1)*(9**(K-1))*(9-max_d_val)
        f2 = combinations_count(d-2,K-2)*(9**(K-2))*(9-max_d_val_2)
        answer=mother - f1-f2
        print(answer)
    if K==3:
        mother = combinations_count(d,K)*(9**K)
        f1 = combinations_count(d-1,K-1)*(9**(K-1))*(9-max_d_val)
        f2 = combinations_count(d-2,K-2)*(9**(K-2))*(9-max_d_val_2)
        f3 = combinations_count(d-3,K-3)*(9**(K-3))*(9-max_d_val_3)
        answer= mother - f1-f2-f3
        print(answer)

#else: #d=Kのとき
    if K==2:
        print(N-(9+N//10))
    if K==3:
        answer=0
        for i in range(N):
            if str(i).count('0')==0:
                answer+=1
        print(answer)
