n = read_line.chars.map(&.to_i)
k = read_line.to_i
puts solve(n, 0, k)

def solve(cs, start, k)
  len = cs.size - start
  return 0 if len < k
  if k == 1
    return cs[start] + (len - 1) * 9
  end
  ans = comb(len - 1, k) * (9 ** k)
  ans += (cs[start] - 1) * comb(len - 1, k - 1) * (9 ** (k - 1))
  ans += solve(cs, start + 1, k - 1)
  return ans
end

def comb(n, m)
  ret = 1
  m.times do |i|
    ret *= n - i
    ret /= (i + 1)
  end
  return ret
end
