import math import sys N = int(input()) M = int(input()) gcd = math.gcd(N,M) N1 = N//gcd M1 = M//gcd l2 = 0 while M1 % 2 == 0: l2 += 1 M1 //= 2 l5 = 0 while M1 % 5 == 0: l5 += 1 M1 //= 5 if M1 != 1: print(-1) sys.exit() if l2 > l5: print(5) elif l2 == l5: div = 10 while N1%div == 0: N1 //= 10 print(N1) else: c5 = l5-l2 while c5: N1 %= 5 N1 *= 2 c5 -= 1 print(N1)