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

if K == 1:
    c = int(N[0])
    c += (len(N) - 1) * 9
    print(c)

if K == 2:
    c = 0
    if N[0] == 1:
        d = 0
        d += int(N[1])
        d += (len(N) - 2) * 9
        d += int((len(N) - 1) * (len(N) - 2) / 2 * 81)
        print(d)
    else:
        d = 0
        d += int(N[1])
        d += (len(N) - 2) * 9
        d += (len(N) - 1) * 9 * (int(N[0]) - 1)
        d += int((len(N) - 1) * (len(N) - 2) / 2 * 81)
        print(d)

if K == 3:
    pass