N = int(input()) M = int(input()) two, five = 0, 0 while N % 2 == 0: N //= 2 two += 1 while N % 5 == 0: N //= 5 five += 1 while M % 2 == 0: M //= 2 five += 1 while M % 5 == 0: M //= 5 two += 1 two, five = two - min(two, five), five - min(two, five) ans = N % 10 * pow(2, two, 10) * pow(5, five, 10) % 10 print(ans) if M == 1 else print(-1)