import itertools

N = int(input())
K = int(input())

count = 0
ketasu = len(str(N))

# 先頭が0の場合
temp = len(list(itertools.combinations(range(ketasu-1), K)))
temp *= 9 ** K
count = temp

# 先頭が0以外の場合
for i in range(1, 10):
    for j in itertools.product(*(['123456789']*(K-1))): # 81
        j = list(j)
        #for k in itertools.permutations(''.join(j)+'0'*(ketasu-K), ketasu-1):
        #for k in set(list(itertools.permutations(''.join(j)+'0'*(ketasu-K), ketasu-1))):
        exists = set()
        for k in itertools.combinations(range(ketasu-K+1), K-1): # 10000
            for l in itertools.permutations(k, len(k)): # 2
                temp = ['0'] * (ketasu - 1)
                for m, c in zip(l, j):
                    temp[m] = c
                temp2 = str(i) + ''.join(temp)
                if temp2 not in exists:
                    if int(temp2) <= N:
                        count += 1
                    exists.add(temp2)

print(count)
