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

N = str(N)
N_keta = len(N)
p = N[0]

if K == 1:
    kotae = int(p) + 9 * (int(N_keta)-1)
    print(int(kotae))

else:
    M = int(N) - int(p)*(10**(int(N_keta)-1))
    M = str(M)
    M_keta = len(M)
    q = M[0]
    if K == 2:
        if int(N) <= 9:
            print(0)
        else:
            kotae = 9 * (int(N_keta)-1) * (int(p)-1) + int(q) + 9 * (int(M_keta)-1) + (int(N_keta)-1)*(int(N_keta)-2)*40.5
            print(int(kotae))
    else:
        if int(N) <= 99:
            print(0)
        else:
             L = int(M) - int(q)*(10**(int(M_keta)-1))
             L = str(L)
             L_keta = len(L)
             r = L[0]
             kotae = 9 * (int(M_keta)-1) * (int(q)-1) + int(r) + 9 * (int(L_keta)-1) + (int(p)-1)*(int(N_keta)-1)*(int(N_keta)-2)*0.5*81+(int(N_keta)-1)*(int(N_keta)-2)*(int(N_keta)-3)*9**3/6
             print(int(kotae))