n = list(input())
k = int(input())
ln = len(n)

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