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


def C(n, r):
    if r <= 0 or n < r:
        return 0
    elif r == 1:
        return n
    elif r == 2:
        return n*(n-1) // 2
    else:
        return n*(n-1)*(n-2) // 6


def func(i, k, smaller):
    if i == len(N):
        if k == 0:
            return 1
        else:
            return 0

    if k == 0:
        return 1

    if smaller:
        return C(len(N) - i, k) * 9**k
    else:
        return func(i+1, k, True) + \
            func(i+1, k-1, True) * (int(N[i]) - 1) + \
            func(i+1, k-1, False)


print(func(0, K, False))
