import math N = int(input()) M = int(input()) N *= 10 ** 100 G = math.gcd(N, M) N //= G M //= G if M != 1: print(-1) else: ANS = "" for C in str(N): if C != "0": ANS = C print(ANS)