const val MOD = 1000000007L fun main() { val (p, k) = readLine()!!.trim().split(' ').map(String::toInt) var q = 0L var r = 1 repeat(p) { q = (q * 10 + r / p) % MOD r = (r % p) * 10 } println(if (k == 0) q + 1 else q) }