N = int(input())
K = int(input())
n = str(N)
i = 0
while N//10**i != 0:
    i += 1
if i == 1 and K == 1:
    ans = N
elif i == K == 2:
    a = int(n[0])
    ans = (N-a*10)+(a-1)*9
elif i == K == 3:
    a = int(n[0])
    ans = (N-a*100)+(a-1)*81
elif i < K:
    ans = 0
else:
    a = int(n[0])
    ans = a+9*(i-1)
print(ans)