from collections import deque
n = input()
k = int(input())
a = [int(n[i]) for i in range(min(k, len(n)))]
n = len(n)

if k > n:
    ans = 0
elif k == 1:
    ans = a[0] + (n - 1)*9
elif k == 2:
    ans = a[1] + (n - 2)*9 + (a[0] - 1)*(n - 1)*9 + (n - 1)*(n - 2)*9*9//2
else:
    ans = a[2] + (n - 3)*9 + (a[1] - 1)*(n - 2)*9 + (n - 2)*(n - 3)*9*9//2 + (a[0] - 1)*(n - 1)*(n - 2)*9*9//2 + (n - 1)*(n - 2)*(n - 3)*9*9*9//6
print(ans)