from math import gcd n = int(input()) m = int(input()) g = gcd(n, m) n //= g m //= g two = 0 five = 0 while m % 2 == 0: m //= 2 two += 1 while m % 5 == 0: m //= 5 five += 1 if m != 1: print(-1) else: while n % 10 == 0: n //= 10 ans = n % 10 if two > five: for _ in range(two - five): ans *= 5 ans %= 10 else: for _ in range(five - two): ans *= 2 ans %= 10 print(ans)