from math import gcd import sys input = sys.stdin.readline N = int(input()) M = int(input()) g = gcd(N, M) N //= g M //= g while M % 5 == 0: M //= 5 N *= 2 while M % 2 == 0: M //= 2 N *= 5 if M != 1: print(-1) exit() while N % 10 == 0: N //= 10 print(N % 10)