N = [int(i) for i in input()]
n = len(N)
K = int(input())
if n < K:
    print(0)
else:
    if K ==3:
        ans = (n-1)*(n-2)*(n-3)*9**3//6 +((N[0]-1)*(n-1)+(n-3))*(n-2)*9**2 //2
        ans += (N[1]-1)*(n-2)*9 +(n-3)*9 +N[2]
    elif K ==2:
        ans = (n-1)*(n-2)//2 *9**2+(N[0]-1)*(n-1)*9 +(n-2)*9 +N[1]
    elif K ==1:
        ans = 9*(n-1) +N[0]

    print(max(0,ans))
