from collections import defaultdict from math import gcd, sqrt def Fraction(A, B): G = gcd(A, B) return A // G, B // G def PrimeFactorization(N): ret = defaultdict(int) for i in range(2,int(sqrt(N))+1): while N % i == 0: ret[i] += 1 N //= i if N > 1: ret[N] += 1 return ret def BinPower(x, k, mod = 10**9+7): ret = 1 while k > 0: if k & 1: ret = ret * x % mod x = x * x % mod k >>= 1 return ret mod = 10**6 N = int(input()) M = int(input()) N,M = Fraction(N, M) P = PrimeFactorization(M) for i in P.keys(): if i != 2 and i != 5: print(-1) exit() N *= BinPower(5, max(0, P[2]-P[5]), mod) N *= BinPower(2, max(0, P[5]-P[2]), mod) N %= mod while N % 10 == 0: N //= 10 print(N % 10)