def gcd(x, y): if y == 0: return x return gcd(y, x % y) N = int(input()) M = int(input()) d = gcd(N, M) N //= d M //= d a2, a5 = 0, 0 while M % 2 == 0: a2 += 1 M //= 2 while M % 5 == 0: a5 += 1 M //= 5 if M != 1: print("-1") else: while N % 10 == 0: N //= 10 ret = N % 10 for i in range(a2): ret = (ret * 10) // 2 if ret % 10 == 0: ret /= 10 ret = ret % 10 for i in range(a5): ret = (ret * 10) // 5 if ret % 10 == 0: ret //= 10 ret = ret % 10 print(ret)