import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) m=int(input()) if n%m==0: nm=str(n//m) for nn in nm[::-1]: if nn=="0": continue else: print(nn) break else: while True: if m%5==0: m//=5 n*=2 elif m%2==0: m//=2 n*=5 else: break if m==1: n=str(n) for nn in n[::-1]: if nn=="0": continue else: print(nn) break else: print(-1)