N = input()
L = len(N)
K = int(input())
if L < K:
    print(0)
elif L == K:
    if N == "10":
        res = 0
    elif int(N) >= 100 and int(N) <= 110:
        res = 0
    else:
        if L == 1:
            res = int(N)
        elif L == 2:
            if N[1] == "0":
                N = str(int(N) - 1)
            res = (int(N[0]) - 1) * 9 + int(N[1])
        elif L == 3:
            if N[1] == "0":
                if N[2] == "0":
                    N = str(int(N) - 1)
                else:
                    N = str(int(N) - int(N[2]) - 1)
            res = (int(N[0]) - 1) * 81 + (int(N[1]) - 1) * 9 + int(N[2])
    print(res)
else:
    if K == 1:
        res = (L - 1) * 9 + int(N[0])
    elif K == 2:
        res = (
            (((L - 1) * (L - 2)) // 2) * 81
            + (L - 1) * 9 * (int(N[0]) - 1)
            + (L - 2) * 9
            + int(N[1])
        )
    elif K == 3:
        res = (
            (((L - 1) * (L - 2) * (L - 3)) // 6) * (9 ** 3)
            + (((L - 1) * (L - 2)) // 2) * 81 * (int(N[0]) - 1)
            + (((L - 2) * (L - 3)) // 2) * 81
            + (L - 2) * 9 * (int(N[1]) - 1)
            + (L - 3) * 9
            + int(N[2])
        )
    print(res)
