import itertools
N = int(input())
K = int(input())

keta = len(str(N))
not_kumi = list(itertools.combinations(range(keta), K))
count = 0

kumikomi = list(itertools.product(range(1,10), repeat = K))

for i in range(len(not_kumi)):   
    for j in range(len(kumikomi)):
        num = "".join(str("0") for i in range(keta))
        num = list(num)
        for k in range(K):
            num[not_kumi[i][k]] = str(kumikomi[j][k])
        
        for k in range(keta):
            if num[0]== "0":
                del num[0]
            else:
                exit
        num = int("".join(num))
        
        
        if num < N:
            count+=1
print(count)