N = int(input())
K = int(input())
S = str(N)
n = len(S)
def c(x,y):
    X = 1
    Y = 1
    for i in range(y):
        X *= (x-i)
        Y *= (y-i)
    return X//Y
k = 0
ans = 0
for i in range(n):
    if k > K:
        break
    x = int(S[i])
    y = n - 1 - i
    z = K - k
    if i == 0:
        ans += (x-1)*(9**(y-z))*c(y,z)
        continue
    if x == 0:
        k += 1
        continue
    if x == 1:
        if k == K:
            continue
        else:
            ans += (9**(y-z+1))*c(y,z-1)
            continue
    ans += (x-2)*(9**(y-z))*c(y,z)
    if k < K:
        ans += 9**(y-z+1)*c(y,z-1)
print(ans)