#!/usr/bin/env python3 import math IMPOSSIBLE = -1 def solve(n, m): g = math.gcd(n, m) n //= g m //= g f2 = 0 f5 = 0 while m % 2 == 0: m //= 2 f2 += 1 while m % 5 == 0: m //= 5 f5 += 1 if m > 1: return IMPOSSIBLE while n % 10 == 0: n //= 10 n %= 10 while f2 > f5: f5 += 1 n = n * 5 % 10 while f2 < f5: f2 += 1 n = n * 2 % 10 return n def main(): print(solve(int(input()), int(input()))) if __name__ == '__main__': main()