import math num = int(input()) den = int(input()) g = math.gcd(num,den) num //= g den //= g d = den + 0 while d % 5 == 0: d //= 5 while d % 2 == 0: d //= 2 if d != 1: print(-1) exit(0) while num % den != 0: num *= 10 res = num // den while res % 10 == 0: res //= 10 print(res%10)