n = input()
n_0 = int(n[0])
n_1 = int(n[1])
n_2 = int(n[2])
n = len(n)
k = int(input())

if n < k:
    print(0)
else:
    if k == 1:
        print(9*(n-1)+n_0)
    elif k == 2:
        print(81*(-2)*(n-1)//2 + (n_0-1)*9*(n-1) + 9*(n-2) + n_1)
    else:
        print(9*9*9*((n-3)*(n-2)*(2*n-5)//6 + (n-3)*(n-2)//2)//2 + (n_0-1)*81*(n-1)*(n-2)//2 + 81*(n-3)*(n-2)//2 + (n_1-1)*9*(n-2) + 9*(n-3) + n_2)