N = input()
K = int(input())

if K == 1:
    Nm = int(N[0])
    print(Nm+9*(len(N)-1))
elif K == 2 :
    #print("no")
    m = len(N)
    if m == 1:
        print("0")
    else:
        Nm = int(N[0])
        Nm_1 = int(N[1])
        print(int((Nm-1)*(m-1)*9+9*9*(m-1)*(m-2)/2+Nm_1+9*(m-2)))
elif K == 3 :
    m = len(N)
    if m == 1 or m == 2:
        print("0")
    else:
        Nm = int(N[0])
        Nm_1 = int(N[1])
        Nm_2 = int(N[2])

        print(int(((Nm-1)*(m-1)*(m-2)*9*9/2)+((m-1)*(m-2)*(m-3)*9*9*9/6)+((Nm_1-1)*(m-2)*9+9*9*(m-2)*(m-3)/2+Nm_2+9*(m-3))))

