from math import gcd def Fraction(A, B): G = gcd(A, B) return A // G, B // G def PrimeFactorization(N): ret = {} ret[2] = ret[5] = 0 while N % 2 == 0: ret[2] += 1 N //= 2 while N % 5 == 0: ret[5] += 1 N //= 5 if N > 1: print(-1) exit() return ret def BinPower(x, k, mod = 10**9+7): ret = 1 while k > 0: if k & 1: ret = ret * x % mod x = x * x % mod k >>= 1 return ret mod = 10**6 N = int(input()) M = int(input()) N,M = Fraction(N, M) P = PrimeFactorization(M) N *= BinPower(5, max(0, P[2]-P[5]), mod) N %= mod N *= BinPower(2, max(0, P[5]-P[2]), mod) N %= mod while N % 10 == 0: N //= 10 print(N % 10)