import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from fractions import gcd a,b = map(int,read().split()) g = gcd(a,b); a //= g; b //= g d = 10 ** 100 if d % b != 0: print(-1) exit() x = a * d // b while x % 10 == 0: x //= 10 answer = x % 10 print(answer)