
N = list(map(int, input()))
K = int(input())
D = len(N)


def k1(n, d):
    return n[0] + 9 * (d - 1)


def k2(n, d):
    if d == 1:
        return 0
    res = k1(n[1:], d-1)+(n[0]-1)*9*(d-1)
    for i in range(d-2):
        res += 81*(i+1)
    return res

def k3(n, d):
    if d <= 2:
        return 0
    res = k2(n[1:], d-1)+(n[0]-1)*9*9*((d-2)/2*(d-1))
    for i in range(1, d-2):
        res += 9*9*9*(i/2*(i+1))
    return int(res)

if K == 1:
    print(k1(N, D))
elif K == 2:
    print(k2(N, D))
else:
    print(k3(N, D))