N, M = int(input()), int(input()) def to_and_five(num, lists=[]): if num == 1: return lists if num % 2 == 0: return to_and_five(num // 2, lists + [2]) if num % 5 == 0: return to_and_five(num // 5, lists + [5]) return False def prime(n, m): if not (tmp := n % m): return m else: return prime(m, tmp) if N % M == 0: ans = N // M while not ans % 10: ans //= 10 ans %= 10 else: N, M = N // (tmp := prime(N, M)), M // tmp if (tmp := to_and_five(M)): N %= 10 for i in tmp: if i == 5: N *= 2 else: N *= 5 N %= 10 ans = N else: ans = -1 print(ans)