def out_order1(N):
    return(9 * (len((str(N))) - 1) + int(str(N)[0]))
def out_order2(N):
    if(len(str(N)) >= 3):
        out = 9 * 9 * (len(str(N)) - 1) * (len(str(N)) - 2) / 2
        out += (int(str(N)[0]) - 1) * (len(str(N)) - 1) * 9
        N = str(N)
        N = N[1:]
        out += out_order1(int(N))
    elif(len(str(N)) == 2):
        out = (int(str(N)[0]) - 1) * 9 + (int(str(N)[1]))
    else:
        out = 0
    return(out)

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

if K == 1:
    out = out_order1(N)
elif K ==2:
    out = out_order2(N)
elif K == 3:
    if(len(str(N)) >= 4):
        out = 9 * 9 * 9 * (len(str(N)) - 1) * (len(str(N)) - 2) * (len(str(N)) - 3) / 6
        out += (int(str(N)[0]) - 1) * (len(str(N)) - 1) * (len(str(N)) - 2) * 9 * 9 / 2
        N = str(N)
        N = N[1:]
        out += out_order2(int(N))
    elif(len(str(N)) == 3):
        out = (int(str(N)[0]))
        N = str(N)
        N = N[1:]
        out += out_order2(int(N))
    else:
        out = 0
    
print(out)