p, k = map(int, input().split()) res = 1 n = p - 1 t = 10 while n != 0: if n % 2 == 1: res *= t t *= t n //= 2 ans = res // p if k < pow(10, p - 1, p): ans += 1 MOD = int(1e9+7) print(ans % MOD)