#include using namespace std; template inline T gcd(T a, T b) { return __gcd(a, b); } template inline T lcm(T a, T b) { return a / gcd(a, b) * b; } template inline T floor(T a, T b) { return a / b * b <= a ? a / b : a / b - 1; } template inline T ceil(T a, T b) { return floor(a + b - 1, b); } template inline T round(T a, T b) { return floor(a + b / 2); } template inline T mod(T a, T b) { return a - floor(a, b) * b; } template inline T factorial(T n) { return n <= 1 ? 1 : factorial(n - 1) * n; } class Prime { private: vector div; public: Prime(long long n = 0) { for (long long i = 0; i <= n; ++i) div.emplace_back(i); for (long long i = 2; i <= n / i; ++i) if (div[i] == i) { for (long long j = i * i; j <= n; j += i) div[j] = i; } } bool isPrime(long long n) const { if (n <= 1) return false; if (n < (long long)div.size()) return div[n] == n; for (long long i = 2; i <= n / i; ++i) if (n % i == 0) return false; return true; } vector factor(long long n) const { vector res; for (long long i = 2; i <= n / i && n >= (long long)div.size(); ++i) { while (n % i == 0) { res.emplace_back(i); n /= i; } } if (n >= max((long long)div.size(), 2ll)) { res.emplace_back(n); } else { while (n > 1) { res.emplace_back(div[n]); n /= div[n]; } } sort(res.begin(), res.end()); return res; } vector primeFactor(long long n) const { vector res; for (long long i = 2; i <= n / i && n >= (long long)div.size(); ++i) { if (n % i) continue; res.emplace_back(i); while (n % i == 0) n /= i; } if (n >= max((long long)div.size(), 2ll)) { res.emplace_back(n); } else { while (n > 1) { long long d = div[n]; res.emplace_back(d); while (n % d == 0) n /= d; } } sort(res.begin(), res.end()); return res; } vector divisor(long long n) const { vector res; for (long long i = 1; i <= n / i; ++i) { if (n % i == 0) { res.emplace_back(i); if (i != n / i) res.emplace_back(n / i); } } sort(res.begin(), res.end()); return res; } }; int main() { long long n, m; cin >> n >> m; auto g = gcd(n, m); n /= g; m /= g; Prime prime; auto v = prime.primeFactor(m); if (any_of(v.begin(), v.end(), [](long long i){return i != 2 && i != 5;})) { cout << -1 << endl; return 0; } while (n % 10 == 0) n /= 10; n %= 10; while (m != 1) { n *= 10; g = gcd(n, m); n /= g; m /= g; n %= 10; } cout << n << endl; }