from fractions import gcd def solve(): N = int(input()) M = int(input()) g = gcd(N, M) n = N // g m = M // g o = m c2 = c5 = 0 while o % 5 == 0: o /= 5 c5 += 1 while o % 2 == 0: o /= 2 c2 += 1 if o != 1: print(-1) return if c2 == c5: d = 1 elif c2 > c5: d = 5 else: c5 -= c2 d = 2 ** c5 % 10 n *= d while n % 10 == 0: n //= 10 print(n % 10) if __name__ == '__main__': solve()