import numpy as np 
import math
import itertools
N_str = input()
K = input()
base = len(N_str)
N = int(N_str)
K = int(K) 

cnt = 0
idx_candidates = [i for i in range(base)]
number_candidates = [i for i in range(1, 10)]
if N_str[:-1] == "9"*(base-1):
    cnt = math.factorial(base)/(math.factorial(base-K)*math.factorial(K)) * 9**K
    print(int(cnt))
else: 
    for idxs in itertools.combinations(idx_candidates, r=K):
        for nums in itertools.product(number_candidates, repeat=K): 
            number = ["0"] * base
            for i, idx in enumerate(idxs): 
                number[idx] =  str(nums[i])
            number = int("".join(number))
            if number <= N:
                cnt += 1    
    print(int(cnt))