from itertools import combinations

def main():
    N = list(map(int, input()))
    K = int(input())
    A = len(N)
    if A < K:
        return 0
    if K == 1:
        return N[0] + 9 * (A - 1)
    if K == 2:
        t = 9 * 9 * (A - 1) * (A - 2) // 2
        t += (N[0] - 1) * 9 + N[1] + (A - 2) * N[0] * 9
        return t
    if K == 3:
        t = 9 * 9 * 9 * (A - 1) * (A - 2) * (A - 3) // 6
        t += (N[0] - 1) * 9 * 9 * (A - 2) + (N[1] - 1) * 9 * (A - 2) + 9 * (A - 3) + N[2]
        for i, j in combinations(N[2:], 2):
            t += N[0] * 9 * 9
        return t

    

print(main())
