// yukicoder: No.25 有限小数 // 2019.4.8 bal4u // 有限小数の条件と求め方 #include int check(long long x) { while ((x & 1) == 0) x >>= 1; while (x % 5 == 0) x /= 5; return x == 1; } int main() { int ans; long long N, M; scanf("%lld%lld", &N, &M); if (!check(M)) ans = -1; else { if ((ans = (int)(N % M)) == 0) { N /= M; while ((ans = (int)(N % 10)) == 0) N /= 10; } else { while (N % M) N -= (N / M) * M, N *= 10; ans = (int)(N / M); } } printf("%d\n", ans); return 0; }