# -*- coding: utf-8 -* import math n = int(input()) m = int(input()) g = math.gcd(n, m) n,m = n//g, m//g while n % 10 == 0: n //= 10 n %= 10 lieSolution = 0 while m % 5 == 0: m //= 5 n *= 2 n %= 10 while m % 2 == 0: m //= 2 n *= 5 n %= 10 if n == 0: lieSolution += 1 if m == 1: if lieSolution == 0: print(n) else: print(lieSolution) else: print(-1)