#!/usr/bin/python3 from fractions import gcd n, m = int(input()), int(input()) g = gcd(n, m) n //= g m //= g c2, c5 = 0, 0 while m % 2 == 0: m //= 2 c2 += 1 while m % 5 == 0: m //= 5 c5 += 1 if m != 1: print(-1) exit(0) if c2 > c5: n *= 5**(c2-c5) elif c2 < c5: n *= 2**(c5-c2) while n % 10 == 0: n //= 10 res = n % 10 print(res)