S = input()
k = int(input())

n = len(S)
S0 = int(S[0])
if k == 1:
    print(9*(n-1) + S0)
elif k == 2:
    x = sum(x for x in range(1, n-1))
    for i in range(1, n):
        if S[i] != '0':
            break
    Si = int(S[i])
    print(x*81 + (S0-1)*(n-1)*9 + (n-1-i)*9 + Si)
else:
    exit(1)