#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair i_ll; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; ll gcd(ll a, ll b) { if (b == 0) return abs(a); else return gcd(b, a % b); } int main() { ll N, M; cin >> N >> M; ll d = gcd(N, M); N /= d; M /= d; int two = 0, five = 0; for (; M % 2 == 0; M /= 2) two++; for (; M % 5 == 0; M /= 5) five++; if (M != 1) { cout << -1 << endl; return 0; } for (; N % 10 == 0; N /= 10); N %= 10; for (; two > 0 || five > 0; two--, five--) { if (two <= 0) N = (N * 2) % 10; if (five <= 0) N = (N * 5) % 10; } cout << N << endl; }