NS = input()
N = int(NS)
Nle = len(NS)
K = int(input())
ans = 0

if K == 1:
    ans = (Nle-1) * 9 + int(NS[0])
elif K == 2:
    ans = Nle * (Nle-1) * 9 * 9//2 - (9 - int(NS[0])) * (Nle-1) * 9 - 1 * (9 - int(NS[1]))
else:
    ans = Nle * (Nle-1) * (Nle-2) * (9**3) // 6 - \
          (9 - int(NS[0])) * (Nle-1) * (Nle-2) * 9 * 9 // 2 -\
          1 * (9 - int(NS[1])) * (Nle-2) * 9 -\
          1 * 1 * (9 - int(NS[2]))

print(ans)