def factorial(x)
  f = 1
  for i in 1..x do
    f *= i
  end
  return f
end

def combi(p, q)
  return factorial(p) / factorial(q) / factorial(p-q)
end

ni = gets.chomp.reverse.split("").map(&:to_i)
m = ni.length
k = gets.to_i
count = 0
case k
when 1
  count = 9 * (m-1) + ni[m-1]
when 2
  if m >= 3
    count += 81 * combi(m-1, 2)
  end
  count += 9 * (m-1) * (ni[m-1] - 1)
  count += 9 * (m-2) + ni[m-2]
when 3
  if m >= 4
    count += 729 * combi(m-1, 3)
  end
  count += 81 * combi(m-1, 2) * (ni[m-1] - 1)
  count += 81 * combi(m-2, 2)
  count += 9 * (m-2) * (ni[m-2] - 1)
  count += 9 * (m-3) + ni[m-3]
end
puts count
