def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    K = int(input())

    if len(N) < K:
        print(0)

    if K == 1:
        print(N[0] + 9 * (len(N)-1))
    elif K == 2:
        count = 0
        for i in range(1, len(N)-1):
            count += 81 * i
        count += (N[0]-1) * 9 * (len(N)-1)

        count += 9 * (len(N)-2)

        count += N[1]
        print(count)
    else:
        count = 0
        for i in range(2, len(N)-1):
            count += 729 * i*(i-1)//2
        count += (N[0]-1) * 81 * (len(N)-1) * (len(N)-2) // 2

        count += 81 * (len(N)-2) * (len(N)-3) // 2

        count += (N[1]-1) * 9 * (len(N)-2)

        count += 9 * (len(N)-3)

        count += N[2]
        print(count)

main()