#include using namespace std; using i64 = int64_t; using vi = vector; using vvi = vector; int main() { i64 n, m; cin >> n >> m; i64 g = __gcd(n, m); n /= g; m /= g; if (n % m == 0) { i64 k = n / m; while (k % 10 == 0) { k /= 10; } cout << k << endl; return 0; } n %= m; i64 M = m; int t = 0, f = 0; while (M % 2 == 0) { M /= 2; t++; } while (M % 5 == 0) { M /= 5; f++; } if (M != 1) { cout << -1 << endl; return 0; } if (t < f) { n %= 10; for (int i = 0; i < f - t; i++) { n *= 2; n %= 10; } cout << n << endl; } else { n %= 10; for (int i = 0; i < t - f; i++) { n *= 5; n %= 10; } cout << n << endl; } }