n = int(input())
k = int(input())

from collections import Counter
count = 0
for i in range(0, n+1):
    s = str(i).replace('0', '')
    if sum(Counter(s).values()) == k:
        count += 1
print(count)