def gcd(n, m): if m == 0: return n return gcd(m, n % m) def main(): N = int(input()) M = int(input()) g = gcd(N, M) N //= g M //= g while N % 10 == 0: N = N // 10 N %= 10 while M % 5 == 0: M = M // 5 N *= 2 N %= 10 while M % 2 == 0: M = M // 2 N *= 5 N %= 10 if M == 1: print(N) else: print(-1) if __name__ == '__main__': main()