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 mod = 10**10 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 *= pow(5, max(0, P[2]-P[5])) N *= pow(2, max(0, P[5]-P[2])) N %= mod while N % 10 == 0: N //= 10 print(N % 10)