#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair P; int main() { ios_base::sync_with_stdio(0); ll N, M; cin >> N >> M; ll g = __gcd (N, M ); N /= g; M /= g; int p2 = 0, p5 = 0; while (M % 2LL == 0 ) M /= 2LL, p2++; while (M % 5LL == 0 ) M /= 5LL, p5++; while (N % 10 == 0 ) N /= 10; N %= 10; while (p2 > p5 ) p5++, N = ((N*5LL) % 10LL ); while (p2 < p5 ) p2++, N = ((N*2LL) % 10LL ); if (M != 1LL ){ cout << -1 << endl; }else{ cout << N << endl; } // end if return 0; }