S = input()
k = int(input())
n = len(S)

S0 = int(S[0])
if k == 1:
  print(9*(n-1) + S0)
elif k == 2:
  S1 = int(S[1])
  s = sum(x for x in range(1, n-1))
  print(s*81 + (S0-1)*(n-1)*9 + (n-2)*9 + S1)
else:
  exit(1)