import math

N=int(input())
K=int(input())
digits = len(str(N))
max_digits_val= int(str(N)[-digits])
max_digits_val_2= int(str(N)[-(digits-1)])
max_digits_val_3 = int(str(N)[-(digits-2)])


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





if K>digits:
    print(0)
elif digits==1:
    print(N)
else:
    if K==1:
        answer = combinations_count(digits,K)*(9**K)- combinations_count(digits-1,K-1)*(9**(K-1))*(9-max_digits_val)
        print(answer)
    if K==2:
        answer = combinations_count(digits,K)*(9**K)- combinations_count(digits-1,K-1)*(9**(K-1))*(9-max_digits_val)- combinations_count(digits-2,K-2)*(9**(K-2))*(9-max_digits_val_2)
        print(answer)
    if K==3:
        answer = combinations_count(digits,K)*(9**K)- combinations_count(digits-1,K-1)*(9**(K-1))*(9-max_digits_val)- combinations_count(digits-2,K-2)*(9**(K-2))*(9-max_digits_val_2)- combinations_count(digits-3,K-3)*(9**(K-3))*(9-max_digits_val_3)
        print(answer)
