import math a = int(input()) b = int(input()) c = math.gcd(a, b) a //= c b //= c b2 = b five = 0 two = 0 while b2 % 5 == 0: five += 1 b2 //= 5 while b2 % 2 == 0: two += 1 b2 //= 2 if b2 != 1: print(-1) exit(0) a *= 2**five a *= 5**two while True: if a % 10 != 0: print(a % 10) break a //= 10