from sys import exit from math import gcd N = int(input()) M = int(input()) g = gcd(N, M) N //= g M //= g while not N % 10: N //= 10 m = M ct = {2: 0, 5: 0} for x in (2, 5): while not m % x: m //= x ct[x] += 1 if m != 1: print(-1) exit() if ct[2] <= ct[5]: for i in range(ct[5] - ct[2]): N *= 2 if not N % 10: N //= 10 else: for i in range(ct[2] - ct[5]): N *= 5 if not N % 10: N //= 10 print(N % 10)