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