Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal". 

The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.


-----Input-----

The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 10^9). 


-----Output-----

If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.


-----Examples-----
Input
15 20

Output
3

Input
14 8

Output
-1

Input
6 6

Output
0

Difficulty: EASY
Tags: Number theory

Mathematics

Starter code:

Solutions:
(a, b) = map(int, input().split())
(x, y, z, X, Y, Z) = (0, 0, 0, 0, 0, 0)
while a != 0 and a % 2 == 0:
	a = a / 2
	x += 1
while a != 0 and a % 3 == 0:
	a = a / 3
	y += 1
while a != 0 and a % 5 == 0:
	a = a / 5
	z += 1
while b != 0 and b % 2 == 0:
	b = b / 2
	X += 1
while b != 0 and b % 3 == 0:
	b = b / 3
	Y += 1
while b != 0 and b % 5 == 0:
	b = b / 5
	Z += 1
if a != b:
	print(-1)
else:
	print(max(X, x) - min(X, x) + max(y, Y) - min(y, Y) + max(z, Z) - min(z, Z))


def factorise(n):
	dic = {}
	while n % 2 == 0:
		if 2 in dic:
			dic[2] += 1
		else:
			dic[2] = 1
		n = n / 2
	for i in range(3, int(n ** 0.5) + 1):
		while n % i == 0:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
			n = n / i
	if n > 2:
		dic[n] = 1
	return dic
(a, b) = map(int, input().split())
fac_a = factorise(a)
fac_b = factorise(b)
all_fac = list(set(list(fac_a.keys()) + list(fac_b.keys())))
all_fac.sort()
final = True
l_fac = len(all_fac)
t = 0
for i in range(l_fac):
	if all_fac[i] != 2 and all_fac[i] != 3 and (all_fac[i] != 5):
		if all_fac[i] in fac_a and all_fac[i] in fac_b:
			if fac_a[all_fac[i]] == fac_a[all_fac[i]]:
				final = final and True
			else:
				final = final and False
		else:
			final = final and False
	elif all_fac[i] in fac_a and all_fac[i] in fac_b:
		t += abs(fac_a[all_fac[i]] - fac_b[all_fac[i]])
	else:
		try:
			t += fac_a[all_fac[i]]
		except:
			t += fac_b[all_fac[i]]
if final:
	print(t)
else:
	print(-1)


from functools import reduce
from collections import Counter
(a, b) = map(int, input().split())
if a == b:
	print('0')
	exit()
(a1, a2, a3) = (0, 0, 0)
k1 = a
f = 0
while f != -1:
	if k1 % 2 == 0:
		k1 /= 2
		a1 += 1
	elif k1 % 3 == 0:
		k1 /= 3
		a2 += 1
	elif k1 % 5 == 0:
		k1 /= 5
		a3 += 1
	else:
		f = -1
k1a = [a1, a2, a3]
(a1, a2, a3) = (0, 0, 0)
old = k1
k1 = b
f = 0
while f != -1:
	if k1 % 2 == 0:
		k1 /= 2
		a1 += 1
	elif k1 % 3 == 0:
		k1 /= 3
		a2 += 1
	elif k1 % 5 == 0:
		k1 /= 5
		a3 += 1
	else:
		f = -1
if k1 != old:
	print('-1')
	exit()
k1b = [a1, a2, a3]
t = 0
for i in range(3):
	t += abs(k1a[i] - k1b[i])
print(t)


def scan(type):
	return list(map(type, input().split()))
(a, b) = scan(int)
a2 = a3 = a5 = b2 = b3 = b5 = 0
while a % 2 == 0:
	a /= 2
	a2 += 1
while a % 3 == 0:
	a /= 3
	a3 += 1
while a % 5 == 0:
	a /= 5
	a5 += 1
while b % 2 == 0:
	b /= 2
	b2 += 1
while b % 3 == 0:
	b /= 3
	b3 += 1
while b % 5 == 0:
	b /= 5
	b5 += 1
ans = 0
if a != b:
	print(-1)
else:
	ans += max(a2, b2) - min(a2, b2)
	ans += max(a3, b3) - min(a3, b3)
	ans += max(a5, b5) - min(a5, b5)
	print(ans)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def solve(a, b):
	init_a = a
	init_b = b
	if a == b:
		return 0
	a_count = 0
	b_count = 0
	count = 0
	for i in [2, 3, 5]:
		while (a % i == 0) & (b % i == 0):
			a /= i
			b /= i
			count += 1
		while a % i == 0:
			a /= i
			a_count += 1
		while b % i == 0:
			b /= i
			b_count += 1
		if a == b:
			count += 1
	if (init_a == 1) & ((b % 2 == 0) & (b % 3 == 0) & (b % 5 == 0) | (b == 1)):
		return b_count
	if (init_b == 1) & ((a % 2 == 0) & (a % 3 == 0) & (a % 5 == 0) | (a == 1)):
		return a_count
	if count == 0:
		return -1
	else:
		if ((a_count == 0) | (b_count == 0)) & (init_a % init_b != 0) & (init_b % init_a != 0):
			return -1
		return a_count + b_count
(a, b) = to_list(input())
print(solve(a, b))


import math

def countP(n):
	ans = 0
	while n % 2 == 0:
		n = n // 2
		ans += 1
	while n % 3 == 0:
		ans += 1
		n = n // 3
	while n % 5 == 0:
		ans += 1
		n = n // 5
	if n > 1:
		return -1
	return ans
(a, b) = map(int, input().split())
k = math.gcd(a, b)
a = a // k
b = b // k
if countP(a) == -1 or countP(b) == -1:
	print(-1)
else:
	print(countP(a) + countP(b))


import math
import fractions

def pFactors(n):
	from math import sqrt
	(pFact, limit, check, num) = ([], int(sqrt(n)) + 1, 2, n)
	if n == 1:
		return []
	for check in range(2, limit):
		while num % check == 0:
			pFact.append(check)
			num /= check
	if num > 1:
		pFact.append(num)
	return pFact

def solve():
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		return
	gcd = fractions.gcd(a, b)
	af = pFactors(a // gcd)
	bf = pFactors(b // gcd)
	res = 0
	for val in af:
		if val == 2 or val == 3 or val == 5:
			res += 1
		else:
			print(-1)
			return
	for val in bf:
		if val == 2 or val == 3 or val == 5:
			res += 1
		else:
			print(-1)
			return
	ares = gcd
	for val in af:
		ares *= val
	bres = gcd
	for val in bf:
		bres *= val
	if ares != a or bres != b:
		print(-1)
		return
	print(res)
solve()


(a, b) = map(int, input().split())
if a == b:
	print('0')
else:

	def div(n):
		(a1, a2, a3) = (0, 0, 0)
		while n % 5 == 0:
			n = n // 5
			a1 = a1 + 1
		while n % 3 == 0:
			n = n // 3
			a2 = a2 + 1
		while n % 2 == 0:
			n = n // 2
			a3 = a3 + 1
		return (n, a1, a2, a3)
	(a, a1, b2, c) = div(a)
	(b, d, e, f) = div(b)
	co = abs(a1 - d) + abs(b2 - e) + abs(c - f)
	if a != b:
		print('-1')
	else:
		print(co)


import sys
import copy
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
t = 1
for test in range(t):
	(a, b) = get_ints()
	a2 = 0
	a3 = 0
	a5 = 0
	b2 = 0
	b3 = 0
	b5 = 0
	while a % 2 == 0:
		a2 += 1
		a = a // 2
	while a % 3 == 0:
		a3 += 1
		a = a // 3
	while a % 5 == 0:
		a5 += 1
		a = a // 5
	while b % 2 == 0:
		b2 += 1
		b = b // 2
	while b % 3 == 0:
		b3 += 1
		b = b // 3
	while b % 5 == 0:
		b5 += 1
		b = b // 5
	if a != b:
		print(-1)
		continue
	else:
		print(abs(a2 - b2) + abs(b3 - a3) + abs(a5 - b5))


def factorize(x):
	res = []
	i = 2
	while i <= 5:
		while x % i == 0:
			res.append(i)
			x /= i
		i += 1
	res.append(int(x))
	return res[::-1]

def countVal(fr, x):
	for i in fr:
		if i == 2:
			x[0] += 1
		elif i == 3:
			x[1] += 1
		elif i == 5:
			x[2] += 1
(a, b) = map(int, input().split())
a1 = factorize(a)
b1 = factorize(b)
xa = [0, 0, 0]
xb = [0, 0, 0]
if a1[0] != b1[0]:
	print(-1)
else:
	countVal(a1, xa)
	countVal(b1, xb)
	print(abs(xa[0] - xb[0]) + abs(xa[1] - xb[1]) + abs(xa[2] - xb[2]))


(a, b) = list(map(int, input().split()))

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def burn(n):
	c = 0
	while n % 2 == 0:
		c += 1
		n = n // 2
	while n % 3 == 0:
		c += 1
		n = n // 3
	while n % 5 == 0:
		c += 1
		n = n // 5
	return [c, n]
if a == b:
	print(0)
else:
	g = gcd(a, b)
	c = a // g
	d = b // g
	l1 = burn(c)
	l2 = burn(d)
	if l1[1] == 1 and l2[1] == 1:
		print(l1[0] + l2[0])
	else:
		print(-1)


import math
ans = 0
(a, b) = map(int, input().split())
x = math.gcd(a, b)
a = a // x
b = b // x
while a % 2 == 0:
	a = a // 2
	ans += 1
while a % 3 == 0:
	a = a // 3
	ans += 1
while a % 5 == 0:
	a = a // 5
	ans += 1
while b % 2 == 0:
	b = b // 2
	ans += 1
while b % 3 == 0:
	b = b // 3
	ans += 1
while b % 5 == 0:
	b = b // 5
	ans += 1
if a == 1 and b == 1:
	print(ans)
else:
	print(-1)


from fractions import gcd

def o(n):
	v = 0
	for f in (2, 3, 5):
		while n % f == 0:
			n //= f
			v += 1
	return v if n == 1 else -1
(a, b) = map(int, input().split())
f = gcd(a, b)
(v1, v2) = (o(a // f), o(b // f))
print(v1 + v2 if v1 >= 0 and v2 >= 0 else -1)


(a, b) = list(map(int, input().split()))
a2 = 0
a3 = 0
a5 = 0
b2 = 0
b3 = 0
b5 = 0
while a % 2 == 0:
	a //= 2
	a2 += 1
while a % 3 == 0:
	a //= 3
	a3 += 1
while a % 5 == 0:
	a //= 5
	a5 += 1
while b % 2 == 0:
	b //= 2
	b2 += 1
while b % 3 == 0:
	b //= 3
	b3 += 1
while b % 5 == 0:
	b //= 5
	b5 += 1
tot = max(a2 - min(a2, b2), b2 - min(a2, b2)) + max(a3 - min(a3, b3), b3 - min(a3, b3)) + max(a5 - min(a5, b5), b5 - min(a5, b5))
if a == b:
	print(tot)
else:
	print(-1)


def gcd(a, b):
	if a > b:
		(a, b) = (b, a)
	while True:
		t = b % a
		if t == 0:
			return a
		(a, b) = (t, a)
	return 1
(a, b) = map(int, input().split())
g = gcd(a, b)
m = a / g * b / g
n = 0
while m % 2 == 0:
	m /= 2
	n += 1
while m % 3 == 0:
	m /= 3
	n += 1
while m % 5 == 0:
	m /= 5
	n += 1
print(n if m == 1 else -1)


(a1, b1) = map(int, input().split())
l = [2, 3, 5]
ans = 0
for x in l:
	k1 = 0
	a = a1
	b = b1
	while a % x == 0:
		a //= x
		k1 += 1
	while b % x == 0:
		b //= x
		k1 -= 1
	ans += abs(k1)
	if k1 > 0:
		for i in range(k1):
			a1 //= x
	else:
		for i in range(abs(k1)):
			b1 //= x
if a1 == b1:
	print(ans)
else:
	print(-1)


from math import log
(a, b) = input().split()
a = int(a)
b = int(b)

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	elif not a % b:
		return b
	else:
		return gcd(b, a % b)

def div_n(x, i):
	l = int(round(log(x) / log(i)))
	count = 0
	for j in range(1, l + 1):
		if not x % i:
			x = x // i
			count += 1
	return (x, count)
if a == b:
	print(0)
else:
	n = gcd(a, b)
	num_a = a // n
	num_b = b // n
	(num_a, count1) = div_n(num_a, 2)
	(num_a, count2) = div_n(num_a, 3)
	(num_a, count3) = div_n(num_a, 5)
	count_a = count1 + count2 + count3
	(num_b, count1) = div_n(num_b, 2)
	(num_b, count2) = div_n(num_b, 3)
	(num_b, count3) = div_n(num_b, 5)
	count_b = count1 + count2 + count3
	if num_a == 1 and num_b == 1:
		print(count_a + count_b)
	else:
		print(-1)


import sys
import string
import math
from collections import defaultdict
from functools import lru_cache
from collections import Counter
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def gcd(a, b):
	while b:
		a %= b
		(a, b) = (b, a)
	return a

def factorize(n):
	factors = []
	i = 2
	while i * i <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def main():
	(n, m) = mi(line())
	k = gcd(n, m)
	a = factorize(n // k)
	b = factorize(m // k)
	for f in a:
		if f not in (3, 5, 2):
			print(-1)
			return
	for f in b:
		if f not in (3, 5, 2):
			print(-1)
			return
	print(len(a) + len(b))
main()


(a, b) = input().split()
a = int(a)
b = int(b)
if a == b:
	print(0)
else:
	a2 = 0
	a3 = 0
	a5 = 0
	b2 = 0
	b3 = 0
	b5 = 0
	while a % 2 == 0:
		a2 += 1
		a /= 2
	while a % 3 == 0:
		a3 += 1
		a /= 3
	while a % 5 == 0:
		a5 += 1
		a /= 5
	while b % 2 == 0:
		b2 += 1
		b /= 2
	while b % 3 == 0:
		b3 += 1
		b /= 3
	while b % 5 == 0:
		b5 += 1
		b /= 5
	if a != b:
		print(-1)
	else:
		print(abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5))


import math
(a, b) = list(map(int, input().split()))
gcdm = math.gcd(a, b)
a = a // gcdm
b = b // gcdm
count = 0
while a % 2 == 0:
	a = a // 2
	count += 1
while b % 2 == 0:
	b = b // 2
	count += 1
while a % 3 == 0:
	a = a // 3
	count += 1
while b % 3 == 0:
	b = b // 3
	count += 1
while b % 5 == 0:
	b = b // 5
	count += 1
while a % 5 == 0:
	count += 1
	a = a // 5
if a == b == 1:
	print(count)
else:
	print(-1)


from math import gcd, sqrt
from math import log
from os import path

def factorization235(n):
	(c, result) = (0, 1)
	while n % 2 == 0:
		n /= 2
		c += 1
	while n % 3 == 0:
		n /= 3
		c += 1
	while n % 5 == 0:
		n /= 5
		c += 1
	if n != 1:
		return -1
	return c
(a, b) = map(int, input().split(' '))
(path1, path2, div) = (0, 0, True)
if a == b:
	pass
else:
	target = gcd(a, b)
	path1 = a / target
	path2 = b / target
	if path1 != 1:
		path1 = factorization235(path1)
		if path1 == -1:
			div = False
	else:
		path1 = 0
	if path2 != 1:
		path2 = factorization235(path2)
		if path2 == -1:
			div = False
	else:
		path2 = 0
if div:
	print(int(path1 + path2))
else:
	print(-1)


def rpm(n):
	output = {2: 0, 3: 0, 5: 0, 10: 0}
	for i in [2, 3, 5]:
		op = 0
		while n % i == 0:
			n //= i
			op += 1
		output[i] = op
	output[10] = n
	return output
(A, B) = map(rpm, map(int, input().split()))
if A[10] != B[10]:
	print(-1)
else:
	print(max(A[2], B[2]) - min(A[2], B[2]) + max(A[3], B[3]) - min(A[3], B[3]) + max(A[5], B[5]) - min(A[5], B[5]))


class CodeforcesTask371BSolution:

	def __init__(self):
		self.result = ''
		self.a_b = []

	def read_input(self):
		self.a_b = [int(x) for x in input().split(' ')]

	def process_task(self):
		a1 = 0
		a2 = 0
		a3 = 0
		while not self.a_b[0] % 2:
			self.a_b[0] //= 2
			a1 += 1
		while not self.a_b[0] % 3:
			self.a_b[0] //= 3
			a2 += 1
		while not self.a_b[0] % 5:
			self.a_b[0] //= 5
			a3 += 1
		x = self.a_b[0]
		b1 = 0
		b2 = 0
		b3 = 0
		while not self.a_b[1] % 2:
			self.a_b[1] //= 2
			b1 += 1
		while not self.a_b[1] % 3:
			self.a_b[1] //= 3
			b2 += 1
		while not self.a_b[1] % 5:
			self.a_b[1] //= 5
			b3 += 1
		y = self.a_b[1]
		if x != y:
			self.result = '-1'
		else:
			self.result = str(abs(a1 - b1) + abs(a2 - b2) + abs(a3 - b3))

	def get_result(self):
		return self.result
Solution = CodeforcesTask371BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(a, b) = map(int, input().split())
s = 0
(z, z1) = ([], [])
if a < b:
	(a, b) = (b, a)
while a % 2 == 0 and a:
	a //= 2
	z += [2]
while a % 3 == 0 and a:
	a //= 3
	z += [3]
while a % 5 == 0 and a:
	a //= 5
	z += [5]
while b % 2 == 0 and b:
	b //= 2
	z1 += [2]
while b % 3 == 0 and b:
	b //= 3
	z1 += [3]
while b % 5 == 0 and b:
	b //= 5
	z1 += [5]
if a != b:
	print(-1)
else:
	print(sum((abs(z.count(i) - z1.count(i)) for i in [2, 3, 5])))


from fractions import gcd
(a, b) = map(int, input().split())
if a == b:
	print(0)
	return
c = gcd(a, b)
div1 = dict()
div2 = dict()
a1 = a
b1 = b
c1 = c
for i in [2, 3, 5]:
	div1[i] = 0
	while a1 % i == 0:
		div1[i] += 1
		a1 //= i
	div2[i] = 0
	while b1 % i == 0:
		div2[i] += 1
		b1 //= i
ans = 0
for i in [2, 3, 5]:
	while div1[i] != div2[i]:
		if div1[i] > div2[i]:
			a //= i
			ans += 1
			div1[i] -= 1
		else:
			b //= i
			ans += 1
			div2[i] -= 1
if a != b:
	print(-1)
else:
	print(ans)


ans = 0
(a, b) = map(int, input().split())
for j in [2, 3, 5]:
	while a % j == 0 and b % j == 0:
		a //= j
		b //= j
	while a % j == 0:
		a //= j
		ans += 1
	while b % j == 0:
		b //= j
		ans += 1
if a != b:
	print(-1)
else:
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
(a, b) = map(int, input().split())
(x, y, z) = (0, 0, 0)
while a % 2 == 0:
	a //= 2
	x += 1
while a % 3 == 0:
	a //= 3
	y += 1
while a % 5 == 0:
	a //= 5
	z += 1
while b % 2 == 0:
	b //= 2
	x -= 1
while b % 3 == 0:
	b //= 3
	y -= 1
while b % 5 == 0:
	b //= 5
	z -= 1
if a != b:
	print(-1)
else:
	print(abs(x) + abs(y) + abs(z))


(a, b) = map(int, input().split())
if a == b:
	print(0)
	exit()
(a1, a3, a5, b1, b3, b5) = (0, 0, 0, 0, 0, 0)
while a != 0:
	if a % 2 == 0:
		(a, a1) = (a / 2, a1 + 1)
	elif a % 3 == 0:
		(a, a3) = (a / 3, a3 + 1)
	elif a % 5 == 0:
		(a, a5) = (a / 5, a5 + 1)
	else:
		break
while b != 0:
	if b % 2 == 0:
		(b, b1) = (b / 2, b1 + 1)
	elif b % 3 == 0:
		(b, b3) = (b / 3, b3 + 1)
	elif b % 5 == 0:
		(b, b5) = (b / 5, b5 + 1)
	else:
		break
if a != b:
	print(-1)
else:
	print(abs(a1 - b1) + abs(a3 - b3) + abs(a5 - b5))


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(a, b) = map(int, input().split())
res = gcd(a, b)
if a == b:
	print(0)
else:
	a //= res
	b //= res
	temp = [2, 3, 5]
	ans = 0
	while a % 2 == 0:
		a //= 2
		ans += 1
	while b % 2 == 0:
		b //= 2
		ans += 1
	while a % 3 == 0:
		a //= 3
		ans += 1
	while b % 3 == 0:
		b //= 3
		ans += 1
	while a % 5 == 0:
		a //= 5
		ans += 1
	while b % 5 == 0:
		b //= 5
		ans += 1
	if a == 1 and b == 1:
		print(ans)
	else:
		print(-1)


from math import sqrt, floor
(n, m) = input().split()
n = int(n)
m = int(m)

def fact(n):
	primes = []
	powers = []
	for i in range(2, floor(sqrt(n) + 1)):
		if n % i == 0:
			power = 0
			while n % i == 0:
				power = power + 1
				n = n // i
			primes.append(i)
			powers.append(power)
	if n != 1:
		primes.append(n)
		powers.append(1)
	return [primes, powers]
nn = fact(n)
mm = fact(m)
npr = nn[0]
npw = nn[1]
mpr = mm[0]
mpw = mm[1]
cn2 = 0
cn3 = 0
cn5 = 0
cm2 = 0
cm3 = 0
cm5 = 0
if 2 in npr:
	cn2 = npw[0]
if 3 in npr:
	cn3 = npw[npr.index(3)]
if 5 in npr:
	cn5 = npw[npr.index(5)]
if 2 in mpr:
	cm2 = mpw[0]
if 3 in mpr:
	cm3 = mpw[mpr.index(3)]
if 5 in mpr:
	cm5 = mpw[mpr.index(5)]
ii = -1
jj = -1
for i in range(len(npr)):
	if 30 % npr[i] != 0:
		ii = i
		break
for i in range(len(mpr)):
	if 30 % mpr[i] != 0:
		jj = i
		break
if ii == -1 and jj == -1:
	print(abs(cn2 - cm2) + abs(cn3 - cm3) + abs(cn5 - cm5))
elif ii == -1 or jj == -1:
	print(-1)
elif npr[ii:] != mpr[jj:]:
	print(-1)
elif npw[ii:] != mpw[jj:]:
	print(-1)
else:
	print(abs(cn2 - cm2) + abs(cn3 - cm3) + abs(cn5 - cm5))


import sys
import math
input = sys.stdin.readline
(a, b) = (int(i) for i in input().split())
(l1, l2) = ([0, 0, 0], [0, 0, 0])
while a > 1:
	if a % 2 == 0:
		l1[0] += 1
		a //= 2
	elif a % 3 == 0:
		l1[1] += 1
		a //= 3
	elif a % 5 == 0:
		l1[2] += 1
		a //= 5
	else:
		break
while b > 1:
	if b % 2 == 0:
		l2[0] += 1
		b //= 2
	elif b % 3 == 0:
		l2[1] += 1
		b //= 3
	elif b % 5 == 0:
		l2[2] += 1
		b //= 5
	else:
		break
if a != b:
	print(-1)
else:
	print(abs(l1[0] - l2[0]) + abs(l1[1] - l2[1]) + abs(l1[2] - l2[2]))


from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7

def prime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
(a1, b1) = map(int, input().split())
a = a1
b = b1
rem = defaultdict(int)
rem[3] = rem[5] = rem[2] = 1
dica = defaultdict(int)
dicb = defaultdict(int)
if not prime(a):
	i = 2
	while a > 1:
		if a % i == 0:
			while a % i == 0:
				a //= i
				dica[i] += 1
		else:
			i += 1
else:
	dica[a1] = 1
if not prime(b):
	i = 2
	while b > 1:
		if b % i == 0:
			while b % i == 0:
				b //= i
				if dica[i]:
					dica[i] -= 1
				else:
					dicb[i] += 1
		else:
			i += 1
elif dica[b1]:
	dica[b1] -= 1
else:
	dicb[b1] = 1
ans = 0
bol = True
for i in dica:
	if dica[i]:
		if rem[i]:
			ans += dica[i]
		else:
			bol = False
			break
bolo = True
for i in dicb:
	if dicb[i]:
		if rem[i]:
			ans += dicb[i]
		else:
			bolo = False
			break
if bol and bolo:
	print(ans)
else:
	print(-1)


(n, m) = map(int, input().split())
a1 = 0
a2 = 0
b1 = 0
b2 = 0
c1 = 0
c2 = 0
while n % 2 == 0:
	n /= 2
	a1 += 1
while m % 2 == 0:
	m /= 2
	a2 += 1
while n % 3 == 0:
	n /= 3
	b1 += 1
while m % 3 == 0:
	m /= 3
	b2 += 1
while n % 5 == 0:
	n /= 5
	c1 += 1
while m % 5 == 0:
	m /= 5
	c2 += 1
if m != n:
	print(-1)
else:
	print(abs(a1 - a2) + abs(b1 - b2) + abs(c1 - c2))


def prime(n):
	a = 0
	b = 0
	c = 0
	while n % 2 == 0:
		n //= 2
		a += 1
	while n % 3 == 0:
		n //= 3
		b += 1
	while n % 5 == 0:
		n //= 5
		c += 1
	return (n, a, b, c)
(a, b) = map(int, input().split())
if a == b:
	print(0)
	exit()
(x, a1, a2, a3) = prime(a)
(y, b1, b2, b3) = prime(b)
if x != y:
	print(-1)
else:
	print(abs(a1 - b1) + abs(a2 - b2) + abs(a3 - b3))


from collections import Counter
import math

def primeFactors(n):
	A = []
	while n % 2 == 0:
		A.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			A.append(i)
			n = n / i
	if n > 2:
		A.append(n)
	return Counter(A)
(a, b) = map(int, input().split())
DictA = primeFactors(a)
DictB = primeFactors(b)
x = abs(DictA[2] - DictB[2])
y = abs(DictA[3] - DictB[3])
z = abs(DictA[5] - DictB[5])
S = x + y + z
DictA[2] = 0
DictB[2] = 0
DictA[3] = 0
DictB[3] = 0
DictA[5] = 0
DictB[5] = 0
if DictA == DictB:
	print(S)
else:
	print(-1)


MAX = 1000000000.0 + 7
m = {}

def main():
	nonlocal m

	def f(a, b):
		if (a, b) in m:
			return m[a, b]
		if a == b:
			return 0
		if a < 0 or b < 0:
			return int(MAX)
		if a < b:
			return f(b, a)
		ret = int(MAX)
		if a % 2 == 0:
			ret = min(ret, 1 + f(a / 2, b))
		if a % 3 == 0:
			ret = min(ret, 1 + f(a / 3, b))
		if a % 5 == 0:
			ret = min(ret, 1 + f(a / 5, b))
		m[a, b] = ret
		return ret
	(a, b) = list(map(int, input().split(' ')))
	x = f(a, b)
	if x == MAX:
		return -1
	return x
print(main())


from math import pow

def take_input(s):
	if s == 1:
		return int(input())
	return map(int, input().split())

def factor(n, k):
	i = 0
	while n % k == 0:
		i += 1
		n //= k
	return i
(a, b) = take_input(2)
count = 0
if a == b:
	print(0)
	exit()
a_fac_2 = factor(a, 2)
a_fac_3 = factor(a, 3)
a_fac_5 = factor(a, 5)
b_fac_2 = factor(b, 2)
b_fac_3 = factor(b, 3)
b_fac_5 = factor(b, 5)
x = a
if a_fac_2 > 0:
	x //= pow(2, a_fac_2)
if a_fac_3 > 0:
	x //= pow(3, a_fac_3)
if a_fac_5 > 0:
	x //= pow(5, a_fac_5)
y = b
if b_fac_2 > 0:
	y //= pow(2, b_fac_2)
if b_fac_3 > 0:
	y //= pow(3, b_fac_3)
if b_fac_5 > 0:
	y //= pow(5, b_fac_5)
if x != y:
	print(-1)
else:
	print(abs(a_fac_2 - b_fac_2) + abs(a_fac_3 - b_fac_3) + abs(a_fac_5 - b_fac_5))


import sys
input = sys.stdin.readline

def multi_input():
	return map(int, input().split())

def array_print(arr):
	print(' '.join(map(str, arr)))

def solve2(x):
	flag = 0
	prev = 0
	arr = [0, 0, 0]
	while flag == 0:
		if x % 2 == 0:
			x = x // 2
			arr[0] += 1
		if x % 3 == 0:
			x = x // 3
			arr[1] += 1
		if x % 5 == 0:
			x = x // 5
			arr[2] += 1
		if x == prev:
			flag = 1
		prev = x
	return (x, arr)
(x, y) = multi_input()
if x == y:
	print(0)
else:
	(x1, arr1) = solve2(x)
	(y1, arr2) = solve2(y)
	result = 0
	if x1 == y1:
		for i in range(3):
			result += abs(arr1[i] - arr2[i])
		print(result)
	elif result == 0:
		print(-1)


import math
(n, m) = map(int, input().strip().split(' '))
if n > m:
	(n, m) = (m, n)
if n == m:
	print(0)
else:
	p2 = 0
	p3 = 0
	p5 = 0
	p22 = 0
	p33 = 0
	p55 = 0
	while True:
		if m % 2 == 0:
			p2 += 1
			m = m // 2
		elif m % 3 == 0:
			p3 += 1
			m = m // 3
		elif m % 5 == 0:
			p5 += 1
			m = m // 5
		else:
			break
	while True:
		if n % 2 == 0:
			p22 += 1
			n = n // 2
		elif n % 3 == 0:
			p33 += 1
			n = n // 3
		elif n % 5 == 0:
			p55 += 1
			n = n // 5
		else:
			break
	if n != 1 or m != 1:
		if m % n != 0:
			print(-1)
		else:
			k1 = m // n
			if math.log10(k1) / math.log10(2) % 1 == 0 or math.log10(k1) / math.log10(5) % 1 == 0 or math.log10(k1) / math.log10(3) % 1 == 0:
				if math.log10(k1) / math.log10(2) % 1 == 0:
					print(abs(p2 - p22) + abs(p5 - p55) + abs(p3 - p33) + int(math.log10(k1) / math.log10(2)))
				elif math.log10(k1) / math.log10(3) % 1 == 0:
					print(abs(p2 - p22) + abs(p5 - p55) + abs(p3 - p33) + int(math.log10(k1) / math.log10(3)))
				elif math.log10(k1) / math.log10(5) % 1 == 0:
					print(abs(p2 - p22) + abs(p5 - p55) + abs(p3 - p33) + int(math.log10(k1) / math.log10(5)))
			else:
				print(-1)
	else:
		print(abs(p2 - p22) + abs(p5 - p55) + abs(p3 - p33))


from math import gcd
(a, b) = map(int, input().split())
(g, ans) = (gcd(a, b), 0)
(a, b) = (a // g, b // g)
while a % 2 == 0:
	a //= 2
	ans += 1
while a % 3 == 0:
	a //= 3
	ans += 1
while a % 5 == 0:
	a //= 5
	ans += 1
while b % 2 == 0:
	b //= 2
	ans += 1
while b % 3 == 0:
	b //= 3
	ans += 1
while b % 5 == 0:
	b //= 5
	ans += 1
print(-1 if a != 1 or b != 1 else ans)


import math
import fractions
(a, b) = map(int, input().split())
a2 = 0
a3 = 0
a5 = 0
b2 = 0
b3 = 0
b5 = 0
while a % 2 == 0:
	a = a / 2
	a2 = a2 + 1
while a % 3 == 0:
	a = a / 3
	a3 = a3 + 1
while a % 5 == 0:
	a = a / 5
	a5 = a5 + 1
while b % 2 == 0:
	b = b / 2
	b2 = b2 + 1
while b % 3 == 0:
	b = b / 3
	b3 = b3 + 1
while b % 5 == 0:
	b = b / 5
	b5 = b5 + 1
if a != b:
	print(-1)
else:
	print(math.ceil(math.fabs(b2 - a2) + math.fabs(b5 - a5) + math.fabs(b3 - a3)))


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
q = inlt()
a = q[0]
b = q[1]
sum = 0
for i in [2, 3, 5]:
	ct1 = 0
	ct2 = 0
	while a % i == 0:
		ct1 = ct1 + 1
		a = a // i
	while b % i == 0:
		ct2 = ct2 + 1
		b = b // i
	sum = sum + abs(ct1 - ct2)
if a == b:
	print(sum)
else:
	print(-1)


(a, b) = map(int, input().split())
if a == b:
	print(0)
	exit()
a_p = [0] * 6
b_p = [0] * 6
a_x = a
for i in [2, 3, 5]:
	while a_x % i == 0:
		a_x //= i
		a_p[i] += 1
b_x = b
for i in [2, 3, 5]:
	while b_x % i == 0:
		b_x //= i
		b_p[i] += 1
if b_x != a_x:
	print(-1)
	exit()
ans = [0, 0, 0]
for (i, n) in enumerate([2, 3, 5]):
	ans[i] = abs(a_p[n] - b_p[n])
print(sum(ans))


import math

def solveTLE(n, m):
	if n == m:
		return 0
	dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
	for i in range(n + 1):
		for j in range(m + 1):
			if i == j:
				dp[i][j] = 0
				continue
			if i > j:
				(op1, op2, op3) = (math.inf, math.inf, math.inf)
				if i % 2 == 0:
					op1 = dp[i // 2][j]
				if i % 3 == 0:
					op2 = dp[i // 3][j]
				if i % 5 == 0:
					op3 = dp[i // 5][j]
				res = min(op1, op2, op3)
				dp[i][j] = 1 + res
			else:
				(op1, op2, op3) = (math.inf, math.inf, math.inf)
				if j % 2 == 0:
					op1 = dp[i][j // 2]
				if j % 3 == 0:
					op2 = dp[i][j // 3]
				if j % 5 == 0:
					op3 = dp[i][j // 5]
				res = min(op1, op2, op3)
				dp[i][j] = 1 + res
	res = dp[n][m]
	if res == math.inf:
		return -1
	return res

def solve(n, m):
	if n == m:
		return 0
	(a2, b2, a3, b3, a5, b5) = (0, 0, 0, 0, 0, 0)
	while n % 2 == 0:
		n = n // 2
		a2 += 1
	while m % 2 == 0:
		m = m // 2
		b2 += 1
	while n % 5 == 0:
		n = n // 5
		a5 += 1
	while m % 5 == 0:
		m = m // 5
		b5 += 1
	while n % 3 == 0:
		n = n // 3
		a3 += 1
	while m % 3 == 0:
		m = m // 3
		b3 += 1
	if n != m:
		return -1
	res = abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5)
	return res
(n, m) = map(int, input().split())
print(solve(n, m))


import math
from fractions import gcd

def primes(limit):
	Ans = []
	C = [True] * (limit + 1)
	L = list(range(2, limit + 1))
	for item in L:
		if C[item]:
			i = 2
			while item * i <= limit:
				C[item * i] = False
				i += 1
	for item in L:
		if C[item]:
			Ans += [item]
	return Ans
(a, b) = map(int, input().split())
aa = a
bb = b
A = []
B = []
p = primes(int(math.sqrt(10 ** 9)))
for i in range(len(p)):
	if p[i] > a:
		break
	while a % p[i] == 0:
		A.append(p[i])
		a //= p[i]
if a != 1:
	A.append(a)
for i in range(len(p)):
	if p[i] > b:
		break
	while b % p[i] == 0:
		B.append(p[i])
		b //= p[i]
if b != 1:
	B.append(b)
if aa == 1 and bb == 1:
	print(0)
elif aa == 1:
	Done = True
	for item in B:
		if item > 5:
			Done = False
			break
	if Done:
		print(len(B))
	else:
		print(-1)
elif bb == 1:
	Done = True
	for item in A:
		if item > 5:
			Done = False
			break
	if Done:
		print(len(A))
	else:
		print(-1)
else:
	B.sort()
	A.sort()
	Done = True
	ind = 0
	ans = 0
	while A != B:
		if ind >= len(A) and ind >= len(B):
			Done = False
			break
		elif ind >= len(A):
			if B[-1] > 5:
				Done = False
				break
			else:
				ans += len(B) - ind
				break
		elif ind >= len(B):
			if A[-1] > 5:
				Done = False
				break
			else:
				ans += len(A) - ind
				break
		if A[ind] == B[ind]:
			ind += 1
			continue
		if A[ind] < B[ind]:
			if A[ind] > 5:
				Done = False
				break
			else:
				ans += 1
				A.pop(ind)
		elif B[ind] > 5:
			Done = False
			break
		else:
			ans += 1
			B.pop(ind)
	if Done:
		print(ans)
	else:
		print(-1)


def func(n):
	n2 = 0
	n3 = 0
	n5 = 0
	while n % 2 == 0:
		n = n // 2
		n2 += 1
	while n % 3 == 0:
		n = n // 3
		n3 += 1
	while n % 5 == 0:
		n = n // 5
		n5 += 1
	return (n, n2, n3, n5)
(a, b) = map(int, input().split())
(aleft, a2, a3, a5) = map(int, func(a))
(bleft, b2, b3, b5) = map(int, func(b))
if aleft == bleft:
	ans = abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5)
	print(ans)
else:
	print(-1)


import sys
(n, m) = map(int, input().split())
divs = [2, 3, 5]
ar = [0] * 6
br = [0] * 6
tn = n
tm = m
for i in divs:
	while tn % i == 0 and tn > 0:
		ar[i] += 1
		tn //= i
	while tm % i == 0 and tm > 0:
		br[i] += 1
		tm //= i
print
if tn != tm:
	print('-1')
else:
	ans = 2000000000.0
	for i in range(min(br[2], ar[2]) + 1):
		for j in range(min(br[3], ar[3]) + 1):
			for k in range(min(br[5], ar[5]) + 1):
				if ar[2] - i + br[2] - i + ar[3] - j + br[3] - j + ar[5] - k + br[5] - k < ans:
					ans = ar[2] - i + br[2] - i + ar[3] - j + br[3] - j + ar[5] - k + br[5] - k
	print(ans)


d1 = {2: 0, 3: 0, 5: 0}
d2 = {2: 0, 3: 0, 5: 0}
(a, b) = map(int, input().split())
if a % 2 == 0:
	c = 0
	while a % 2 == 0:
		c += 1
		a = a // 2
	d1[2] = c
if a % 3 == 0:
	c = 0
	while a % 3 == 0:
		c += 1
		a = a // 3
	d1[3] = c
if a % 5 == 0:
	c = 0
	while a % 5 == 0:
		c += 1
		a = a // 5
	d1[5] = c
if b % 2 == 0:
	c = 0
	while b % 2 == 0:
		c += 1
		b = b // 2
	d2[2] = c
if b % 3 == 0:
	c = 0
	while b % 3 == 0:
		c += 1
		b = b // 3
	d2[3] = c
if b % 5 == 0:
	c = 0
	while b % 5 == 0:
		c += 1
		b = b // 5
	d2[5] = c
if a != b:
	print(-1)
else:
	cnt = 0
	for i in [2, 3, 5]:
		cnt += abs(d1[i] - d2[i])
	print(cnt)


(a, b) = map(int, input().split())
factors = [2, 3, 5]
from math import gcd
g = gcd(a, b)
ad = a // g
bd = b // g
ops = 0
while True:
	temp = ops
	for factor in factors:
		if ad % factor == 0:
			ad = ad // factor
			ops += 1
		if bd % factor == 0:
			bd = bd // factor
			ops += 1
	if ops == temp:
		break
if ad == bd == 1:
	print(ops)
else:
	print(-1)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
(a, b) = mi()
if a == b:
	print(0)
else:
	(ra, rb) = ([0] * 3, [0] * 3)
	f = True
	while a != 1 and f:
		if a % 5 == 0:
			a //= 5
			ra[2] += 1
		elif a % 3 == 0:
			a //= 3
			ra[1] += 1
		elif a % 2 == 0:
			a //= 2
			ra[0] += 1
		else:
			f = False
	f = True
	while b != 1 and f:
		if b % 5 == 0:
			b //= 5
			rb[2] += 1
		elif b % 3 == 0:
			b //= 3
			rb[1] += 1
		elif b % 2 == 0:
			b //= 2
			rb[0] += 1
		else:
			f = False
	if a != b:
		print(-1)
	else:
		ans = 0
		for i in range(3):
			ans += abs(ra[i] - rb[i])
		print(ans)


(a, b) = [int(x) for x in input().split()]
splits = 0
for i in [2, 3, 5]:
	while a % i == 0 and b % i == 0:
		a //= i
		b //= i
	while a % i == 0:
		a //= i
		splits += 1
	while b % i == 0:
		b //= i
		splits += 1
print([-1, splits][a == b])


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from math import gcd

def countBites(n):
	count = 0
	while n % 2 == 0:
		count += 1
		n //= 2
	while n % 3 == 0:
		count += 1
		n //= 3
	while n % 5 == 0:
		count += 1
		n //= 5
	if n != 1:
		return False
	return count

def main():
	try:
		(a, b) = invr()
		if a == b:
			print('0')
			return True
		weight = gcd(a, b)
		stepa = countBites(a // weight)
		stepb = countBites(b // weight)
		if stepa is not False and stepb is not False:
			print(stepa + stepb)
		else:
			print('-1')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(num1, num2) = [int(i) for i in input().split()]
opr = 0
arr_1 = []
arr_2 = []
a = 0
b = 0
c = 0
check = 1
save = min(num1, num2)
num1 = max(num1, num2)
num2 = save
while num1 != 1 and num1 != num2:
	if num1 % 2 == 0:
		a += 1
		num1 /= 2
	elif num1 % 3 == 0:
		b += 1
		num1 /= 3
	elif num1 % 5 == 0:
		c += 1
		num1 /= 5
	else:
		break
while num2 != 1 and check and (num1 != num2):
	if num2 % 2 == 0:
		a -= 1
		num2 /= 2
	elif num2 % 3 == 0:
		b -= 1
		num2 /= 3
	elif num2 % 5 == 0:
		c -= 1
		num2 /= 5
	else:
		break
if num1 == num2:
	print(abs(a) + abs(b) + abs(c))
else:
	print(-1)


from math import *
[n, k] = [int(i) for i in input().split()]
arr = [[0 for i in range(6)] for j in range(2)]
for i in [2, 3, 5]:
	while n % i == 0:
		n /= i
		arr[0][i] += 1
for i in [2, 3, 5]:
	while k % i == 0:
		k /= i
		arr[1][i] += 1
if n != k:
	print(-1)
else:
	r = abs(arr[1][5] - arr[0][5])
	r += abs(arr[1][3] - arr[0][3])
	r += abs(arr[1][2] - arr[0][2])
	print(r)


3

def readln():
	return tuple(map(int, input().split()))
mem = dict()

def calc(a, b):
	if a == b:
		return 0
	if (a, b) in mem:
		return mem[a, b]
	var = [2 ** 30]
	if a % 2 == 0:
		var.append(calc(a // 2, b))
	if a % 3 == 0:
		var.append(calc(a // 3, b))
	if a % 5 == 0:
		var.append(calc(a // 5, b))
	if b % 2 == 0:
		var.append(calc(a, b // 2))
	if b % 3 == 0:
		var.append(calc(a, b // 3))
	if b % 5 == 0:
		var.append(calc(a, b // 5))
	mem[a, b] = min(var) + (min(var) < 2 ** 30)
	return mem[a, b]
(a, b) = readln()
res = calc(a, b)
print(-1 if res == 2 ** 30 else res)


def primeFactors(n):
	two = 0
	three = 0
	five = 0
	while n % 2 == 0:
		n //= 2
		two += 1
	while n % 3 == 0:
		n //= 3
		three += 1
	while n % 5 == 0:
		n //= 5
		five += 1
	return (n, two, three, five)
(a, b) = map(int, input().split())
(x1, a1, a2, a3) = primeFactors(a)
(y1, b1, b2, b3) = primeFactors(b)
if x1 != y1:
	print(-1)
else:
	print(abs(a1 - b1) + abs(a3 - b3) + abs(a2 - b2))


(a, b) = map(int, input().split())
x1 = 0
y1 = 0
z1 = 0
x2 = 0
y2 = 0
z2 = 0
while a % 5 == 0:
	a /= 5
	x1 += 1
while a % 3 == 0:
	a /= 3
	y1 += 1
while a % 2 == 0:
	a /= 2
	z1 += 1
while b % 5 == 0:
	b /= 5
	x2 += 1
while b % 3 == 0:
	b /= 3
	y2 += 1
while b % 2 == 0:
	b /= 2
	z2 += 1
if a == b:
	print(abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2))
else:
	print(-1)


(a, b) = map(int, input().split())
p = 0
ans = 0
x1 = 0
y1 = 0
z1 = 0
x2 = 0
y2 = 0
z2 = 0
while a % 2 == 0:
	x1 += 1
	a = a // 2
while a % 3 == 0:
	y1 += 1
	a = a // 3
while a % 5 == 0:
	z1 += 1
	a = a // 5
f1 = a
while b % 2 == 0:
	x2 += 1
	b = b // 2
while b % 3 == 0:
	y2 += 1
	b = b // 3
while b % 5 == 0:
	z2 += 1
	b = b // 5
f2 = b
if f1 != f2:
	print(-1)
else:
	print(abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def getpower(x, lst):
	l = [2, 3, 5]
	for i in l:
		cnt = 0
		while x % i == 0:
			cnt += 1
			x //= i
		lst.append(cnt)
	if x != 1:
		lst.append(x)

def main():
	(a, b) = mi()
	lst1 = []
	lst2 = []
	getpower(a, lst1)
	getpower(b, lst2)
	if len(lst1) != len(lst2):
		print(-1)
	elif len(lst1) == len(lst2) == 4:
		if lst1[-1] != lst2[-1]:
			print(-1)
		else:
			moves = 0
			for i in range(3):
				moves += abs(lst1[i] - lst2[i])
			print(moves)
	else:
		moves = 0
		for i in range(3):
			moves += abs(lst1[i] - lst2[i])
		print(moves)
main()


def gcd(a, b):
	while a % b:
		(a, b) = (b, a % b)
	return b
(a, b) = map(int, input().split())
g = gcd(a, b)
a //= g
b //= g
cnt = 0
for i in [2, 3, 5]:
	while a % i == 0:
		a //= i
		cnt += 1
	while b % i == 0:
		b //= i
		cnt += 1
if a == 1 and b == 1:
	print(cnt)
else:
	print(-1)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def factors(n):
	ans = 0
	while n % 2 == 0:
		ans += 1
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			if i > 5:
				return -1
			ans += 1
			n = n // i
	if n > 2:
		if n > 5:
			return -1
		ans += 1
	return ans
(a, b) = value()
GCD = gcd(a, b)
a //= GCD
b //= GCD
a_factors = factors(a)
b_factors = factors(b)
if a_factors == -1 or b_factors == -1:
	print(-1)
else:
	print(a_factors + b_factors)


(a, b) = map(int, input().split())
(x1, x2, x3) = (0, 0, 0)
(y1, y2, y3) = (0, 0, 0)

def div(n, m):
	ans = 0
	while n % m == 0:
		ans += 1
		n //= m
	return [ans, n]
(x1, a) = div(a, 2)
(x2, a) = div(a, 3)
(x3, a) = div(a, 5)
(y1, b) = div(b, 2)
(y2, b) = div(b, 3)
(y3, b) = div(b, 5)
if a != b:
	print(-1)
else:
	print(abs(x1 - y1) + abs(x2 - y2) + abs(x3 - y3))


from math import gcd
(a, b) = map(int, input().split())
_gcd = gcd(a, b)
a //= _gcd
b //= _gcd
cnt = 0
for i in [2, 3, 5]:
	while a % i == 0:
		a //= i
		cnt += 1
	while b % i == 0:
		b //= i
		cnt += 1
if a != 1 or b != 1:
	print(-1)
else:
	print(cnt)


import math
(a, b) = map(int, input().split())
c = math.gcd(a, b)
a //= c
b //= c
ans = 0

def d(x, t):
	nonlocal ans
	while x > 1 and x % t == 0:
		x //= t
		ans += 1
	return x
for i in [2, 3, 5]:
	a = d(a, i)
	b = d(b, i)
print([-1, ans][a == 1 and b == 1])


from sys import stdin
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from math import pi, sqrt
from collections import defaultdict as dd, ChainMap as cc

def pf(n):
	v = []
	d = dd(lambda : 0)
	while n % 2 == 0:
		n //= 2
		d[2] += 1
	for j in range(3, int(sqrt(n)) + 1):
		if n % j == 0:
			while n % j == 0:
				n //= j
				d[j] += 1
	if n > 2:
		d[n] += 1
	return d
(n, m) = mp()
if n == m:
	print(0)
else:
	a = pf(n)
	b = pf(m)
	c = cc(dict(a), dict(b))
	ans = flag = 0
	for i in c:
		if i == 2:
			ans += abs(a[i] - b[i])
		elif i == 3:
			ans += abs(a[i] - b[i])
		elif i == 5:
			ans += abs(a[i] - b[i])
		elif a[i] != b[i]:
			flag = 1
			break
	if flag:
		print(-1)
	else:
		print(ans)


def main():
	from math import gcd
	(a, b) = map(int, input().split())
	(g, res) = (gcd(a, b), 0)
	for x in (a // g, b // g):
		for p in (2, 3, 5):
			while not x % p:
				x //= p
				res += 1
		if x != 1:
			print(-1)
			return
	print(res)
main()


import math
import sys

def sol(x):
	res = 0
	while x % 2 == 0:
		res += 1
		x = x // 2
	while x % 3 == 0:
		res += 1
		x = x // 3
	while x % 5 == 0:
		res += 1
		x = x // 5
	if x != 1:
		return -1
	else:
		return res
(a, b) = map(int, input().split())
d = math.gcd(a, b)
ans1 = sol(a // d)
if ans1 == -1:
	print(-1)
	sys.exit()
ans2 = sol(b // d)
if ans2 == -1:
	print(-1)
	sys.exit()
print(ans1 + ans2)


class Numero:

	def __init__(self, num):
		self.num = num
		self.qtd2 = self.func(num, 2)
		self.qtd3 = self.func(num, 3)
		self.qtd5 = self.func(num, 5)
		self.resto = num // (2 ** self.qtd2 * 3 ** self.qtd3 * 5 ** self.qtd5)

	def func(self, num, x):
		if num % x != 0:
			return 0
		else:
			return 1 + self.func(num // x, x)

	def getX(self):
		return self.qtd2 + self.qtd3 + self.qtd5
(queijo_1, queijo_2) = map(int, input().split())
queijo_1 = Numero(queijo_1)
queijo_2 = Numero(queijo_2)
if queijo_1.resto == queijo_2.resto:
	x = 1
	x *= 2 ** min(queijo_1.qtd2, queijo_2.qtd2)
	x *= 3 ** min(queijo_1.qtd3, queijo_2.qtd3)
	x *= 5 ** min(queijo_1.qtd5, queijo_2.qtd5)
	n1 = Numero(queijo_1.num // (queijo_1.resto * x))
	n2 = Numero(queijo_2.num // (queijo_2.resto * x))
	ans = n1.getX() + n2.getX()
	print(ans)
else:
	print(-1)


(a, b) = map(int, input().split())
(a1, a2, a3, b1, b2, b3) = (0, 0, 0, 0, 0, 0)
while a % 2 == 0:
	a1 += 1
	a = a // 2
while a % 3 == 0:
	a2 += 1
	a = a // 3
while a % 5 == 0:
	a3 += 1
	a = a // 5
while b % 2 == 0:
	b1 += 1
	b = b // 2
while b % 3 == 0:
	b2 += 1
	b = b // 3
while b % 5 == 0:
	b3 += 1
	b = b // 5
if a != b:
	print(-1)
else:
	print(abs(a1 - b1) + abs(a2 - b2) + abs(a3 - b3))


import sys
import math
import functools

def sol(a, b):
	if (a, b) in mem:
		return mem[a, b]
	if (b, a) in mem:
		return mem[b, a]
	if a == b:
		mem[a, b] = 0
		return 0
	else:
		min_so_far = float('inf')
		for x in [2, 3, 5]:
			if a % x == 0:
				min_so_far = min(min_so_far, 1 + sol(a / x, b))
			if b % x == 0:
				min_so_far = min(min_so_far, 1 + sol(a, b / x))
		mem[a, b] = min_so_far
		return min_so_far
(a, b) = list(map(int, sys.stdin.readline().strip().split(' ')))
mem = {}
ans = sol(a, b)
if ans == float('inf'):
	print(-1)
else:
	print(ans)


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
from fractions import Fraction as frac

def solution(a, b):
	f = frac(a, b)
	ops = 0
	(num, den) = (f.numerator, f.denominator)
	while num % 2 == 0:
		ops += 1
		num = num // 2
	while num % 3 == 0:
		ops += 1
		num = num // 3
	while num % 5 == 0:
		ops += 1
		num = num // 5
	while den % 2 == 0:
		ops += 1
		den = den // 2
	while den % 3 == 0:
		ops += 1
		den = den // 3
	while den % 5 == 0:
		ops += 1
		den = den // 5
	if num == den == 1:
		return ops
	else:
		return -1

def solve():
	(a, b) = read_tuple(int)
	print(solution(a, b))
solve()


(a, b) = map(int, input().strip().split())
tries = 0
if a == b:
	print(0)
	exit()
while True:
	if a % 2 == 0 and b % 2 == 0:
		a //= 2
		b //= 2
		continue
	if a % 3 == 0 and b % 3 == 0:
		b //= 3
		a //= 3
		continue
	if a % 5 == 0 and b % 5 == 0:
		b //= 5
		a //= 5
		continue
	else:
		break
while a != b:
	(a, b) = (max(a, b), min(a, b))
	if a % 2 == 0:
		a //= 2
	elif a % 3 == 0:
		a //= 3
	elif a % 5 == 0:
		a //= 5
	else:
		tries = -1
		break
	tries += 1
print(tries)


(a, b) = map(int, input().split())
d = dict()
d[5] = 0
d[2] = 0
d[3] = 0
d2 = dict()
d2[5] = 0
d2[3] = 0
d2[2] = 0
while a % 5 == 0:
	a //= 5
	d[5] += 1
while a % 2 == 0:
	a //= 2
	d[2] += 1
while a % 3 == 0:
	a //= 3
	d[3] += 1
while b % 5 == 0:
	b //= 5
	d2[5] += 1
while b % 2 == 0:
	b //= 2
	d2[2] += 1
while b % 3 == 0:
	b //= 3
	d2[3] += 1
if a != b:
	print(-1)
else:
	print(abs(d[5] - d2[5]) + abs(d[2] - d2[2]) + abs(d2[3] - d[3]))


def mult(x):
	result = []
	for j in [2, 3, 5]:
		res = 0
		while x % j == 0:
			res += 1
			x = x // j
		result.append(res)
	result.append(x)
	return result
(a, b) = map(int, input().split())
(A, B) = (mult(a), mult(b))
if A[-1] != B[-1]:
	print(-1)
else:
	print(abs(A[0] - B[0]) + abs(A[1] - B[1]) + abs(A[2] - B[2]))


(a, b) = map(int, input().split())
x = y = z = 0
while a % 2 == 0:
	x += 1
	a //= 2
while a % 3 == 0:
	y += 1
	a //= 3
while a % 5 == 0:
	z += 1
	a //= 5
while b % 2 == 0:
	x -= 1
	b //= 2
while b % 3 == 0:
	y -= 1
	b //= 3
while b % 5 == 0:
	z -= 1
	b //= 5
print(abs(x) + abs(y) + abs(z) if a == b else -1)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def f(a):
	global e
	k = 0
	while a % 2 == 0:
		a = a // 2
		k += 1
	while a % 3 == 0:
		a = a // 3
		k += 1
	while a % 5 == 0:
		a = a // 5
		k += 1
	e += a
	return k
(a, b) = map(int, input().split())
n = gcd(a, b)
e = 0
k = f(a // n)
k = k + f(b // n)
if e > 2:
	print(-1)
else:
	print(k)


(cntOne, cntTwo) = list(map(int, input().split()))
result = 0
arrDel = []
arrBel = []
c = 0
c1 = 0
pn = 0
if cntOne > cntTwo:
	pn = cntOne
else:
	pn = cntTwo
for i in range(pn):
	if cntOne == 1 and cntTwo == 1 or (c >= 1 and c1 >= 1):
		break
	if cntOne < cntTwo and c1 == 0 or c == 1:
		if cntTwo % 2 == 0:
			cntTwo //= 2
			arrDel.append(2)
		elif cntTwo % 3 == 0:
			cntTwo //= 3
			arrDel.append(3)
		elif cntTwo % 5 == 0:
			cntTwo //= 5
			arrDel.append(5)
		else:
			c1 += 1
	elif cntOne % 2 == 0:
		cntOne //= 2
		arrBel.append(2)
	elif cntOne % 3 == 0:
		cntOne //= 3
		arrBel.append(3)
	elif cntOne % 5 == 0:
		cntOne //= 5
		arrBel.append(5)
	else:
		c += 1
result = result + abs(arrDel.count(2) - arrBel.count(2))
result = result + abs(arrDel.count(3) - arrBel.count(3))
result = result + abs(arrDel.count(5) - arrBel.count(5))
if cntTwo != cntOne:
	print('-1')
else:
	print(result)


from math import gcd
(a, b) = map(int, input().split())
c = gcd(a, b)
a = a // c
b = b // c
ans = 0
for i in [2, 3, 5]:
	x = 0
	y = 0
	while a % i == 0:
		x += 1
		a = a // i
	while b % i == 0:
		y += 1
		b = b // i
	ans += abs(x - y)
if a != b:
	print(-1)
else:
	print(ans)


from math import *

def main():
	R = lambda : map(int, input().split())
	(a, b) = R()
	d = gcd(a, b)
	a //= d
	b //= d
	ans = 0
	while a % 2 == 0:
		a //= 2
		ans += 1
	while a % 3 == 0:
		a //= 3
		ans += 1
	while a % 5 == 0:
		a //= 5
		ans += 1
	while b % 2 == 0:
		b //= 2
		ans += 1
	while b % 3 == 0:
		b //= 3
		ans += 1
	while b % 5 == 0:
		b //= 5
		ans += 1
	if a == 1 and b == 1:
		print(ans)
	else:
		print(-1)
main()


(n, v) = map(int, input().split())
N = [0, 0, 0]
V = [0, 0, 0]
while n % 5 == 0:
	n //= 5
	N[2] += 1
while n % 3 == 0:
	n //= 3
	N[1] += 1
while n % 2 == 0:
	n //= 2
	N[0] += 1
while v % 5 == 0:
	v //= 5
	V[2] += 1
while v % 3 == 0:
	v //= 3
	V[1] += 1
while v % 2 == 0:
	v //= 2
	V[0] += 1
if n != v:
	print(-1)
else:
	print(abs(N[1] - V[1]) + abs(N[2] - V[2]) + abs(N[0] - V[0]))


import math
(a, b) = list(map(int, input().rstrip().split()))
g = math.gcd(a, b)
q1 = a // g
q2 = b // g
flag1 = 0
flag2 = 0
o = 0
while q1 != 1:
	if q1 % 5 == 0:
		q1 = q1 // 5
		o += 1
	elif q1 % 3 == 0:
		q1 = q1 // 3
		o += 1
	elif q1 % 2 == 0:
		q1 = q1 // 2
		o += 1
	else:
		flag1 = 1
		break
while q2 != 1:
	if q2 % 5 == 0:
		q2 = q2 // 5
		o += 1
	elif q2 % 3 == 0:
		q2 = q2 // 3
		o += 1
	elif q2 % 2 == 0:
		q2 = q2 // 2
		o += 1
	else:
		flag2 = 1
		break
if flag1 == 1 or flag2 == 1:
	print(-1)
else:
	print(o)


import math
(a, b) = map(int, input().split())

def get_factors(a):
	fac = {}
	for i in range(2, int(math.sqrt(a) + 1)):
		while a % i == 0:
			fac[i] = fac.get(i, 0) + 1
			a = a // i
	if a != 1:
		fac[a] = fac.get(a, 0) + 1
	return fac

def get_intersection(fa, fb):
	res = {}
	for k in set(fa.keys()).intersection(set(fb.keys())):
		res[k] = min(fa[k], fb[k])
	return res

def get_symmetric_diff(factors, intersection):
	symmetric_diff = {}
	for (k, v) in factors.items():
		c = v - intersection.get(k, 0)
		if c != 0:
			symmetric_diff[k] = v - intersection.get(k, 0)
	return symmetric_diff
factors_a = get_factors(a)
factors_b = get_factors(b)
ab = get_intersection(factors_a, factors_b)
a_minus_b = get_symmetric_diff(factors_a, ab)
b_minus_a = get_symmetric_diff(factors_b, ab)
if not all([i in [2, 3, 5] for i in list(a_minus_b.keys()) + list(b_minus_a.keys())]):
	print(-1)
	exit()
print(sum(a_minus_b.values()) + sum(b_minus_a.values()))


def find_power_of(num, base):
	count = 0
	while num % base == 0:
		num //= base
		count += 1
	return (num, count)
(a, b) = [int(i) for i in input().split()]
(a, a5) = find_power_of(a, 5)
(b, b5) = find_power_of(b, 5)
(a, a3) = find_power_of(a, 3)
(b, b3) = find_power_of(b, 3)
(a, a2) = find_power_of(a, 2)
(b, b2) = find_power_of(b, 2)
if a != b:
	print(-1)
else:
	count = abs(a5 - b5) + abs(a3 - b3) + abs(a2 - b2)
	print(count)


from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from itertools import permutations as p
from bisect import bisect_left as bl, bisect_right as br
from sys import stdin, stdout
input = stdin.readline
from bisect import bisect_right as bl
mp = lambda : map(int, input().split())
it = lambda : int(input())

def sev():
	mx = 2 * 10 ** 5 + 5
	sv = [1] * (mx + 1)
	sv[0] = sv[1] = 0
	for i in range(2, mx):
		if i * i <= mx and sv[i]:
			for j in range(i * 2, mx, i):
				sv[j] = 0
	return sv

def pfactors(n):
	d = dd(lambda : 0)
	flg = 0
	while n % 2 == 0:
		flg += 1
		n //= 2
	if flg:
		d[2] = flg
	for cc in range(3, 6, 2):
		if n % cc == 0:
			cnt = 0
			while n % cc == 0:
				cnt += 1
				n //= cc
			d[cc] = cnt
	return (d, n)
(a, b) = mp()
(a1, rm1) = pfactors(a)
(a2, rm2) = pfactors(b)
if rm1 == rm2:
	ans = abs(a1[2] - a2[2]) + abs(a1[3] - a2[3]) + abs(a1[5] - a2[5])
	print(ans)
else:
	print(-1)


from math import sqrt
(a, b) = [int(i) for i in input().split()]

def div(t):
	d = [2, 3, 5]
	p = [0] * 3
	for i in range(3):
		while t % d[i] == 0:
			p[i] += 1
			t = t // d[i]
	return (t, p)
(a, x) = div(a)
(b, y) = div(b)
if a == b:
	s = 0
	for i in range(3):
		s = s + abs(x[i] - y[i])
else:
	s = -1
print(s)


import math
ans = 0
(n, m) = map(int, input().split())
gcd = math.gcd(n, m)
n /= gcd
m /= gcd
divisors = [2, 3, 5]
for divisor in divisors:
	while n % divisor == 0:
		n /= divisor
		ans += 1
	while m % divisor == 0:
		m /= divisor
		ans += 1
if n != 1 or m != 1:
	print(-1)
else:
	print(ans)


import math

def factorize(x):
	factors = []
	y = 1
	for i in range(2, int(math.sqrt(x) + 1)):
		while x % i == 0:
			factors.append(i)
			x //= i
			if i not in [2, 3, 5]:
				y *= i
	if x != 1:
		factors.append(x)
		if x not in [2, 3, 5]:
			y *= x
	return (factors, y)
(a, b) = map(int, input().split())
(factorsa, x) = factorize(a)
(factorsb, y) = factorize(b)
if x != y:
	print(-1)
else:
	print(abs(factorsa.count(2) - factorsb.count(2)) + abs(factorsa.count(3) - factorsb.count(3)) + abs(factorsa.count(5) - factorsb.count(5)))


from math import gcd, sqrt
(a, b) = [int(i) for i in input().split()]

def primeFactors(n):
	fs = []
	while n % 2 == 0:
		fs.append(2)
		n = n / 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			fs.append(int(i))
			n = n / i
	if n > 2:
		fs.append(int(n))
	return fs

def reduction_steps(num, greatest_commmon_denomenatior):
	possible_moves = [2, 3, 5]
	moves = 0
	pfacts = primeFactors(num)
	gcd_pfacts = primeFactors(greatest_commmon_denomenatior)
	for gcd_pfact in gcd_pfacts:
		pfacts.remove(gcd_pfact)
	for pfact in pfacts:
		if pfact in possible_moves:
			moves += 1
		else:
			return (False, moves)
	return (True, moves)
the_gcd = gcd(a, b)
a_steps = reduction_steps(a, the_gcd)
b_steps = reduction_steps(b, the_gcd)
if a_steps[0] and b_steps[0]:
	print(a_steps[1] + b_steps[1])
else:
	print(-1)


(a, b) = map(int, input().split())
(p, q) = (a, b)
aa = [0, 0, 0]
bb = [0, 0, 0]
(flag, flags) = (0, 0)
while True:
	flag = 0
	if a == 1:
		flag = 2
		break
	if a % 2 == 0:
		aa[0] += 1
		a //= 2
		flag = 1
	elif a % 3 == 0:
		aa[1] += 1
		a //= 3
		flag = 1
	elif a % 5 == 0:
		aa[2] += 1
		a //= 5
		flag = 1
	if flag == 0:
		flag = 3
		break
while True:
	flags = 0
	if b == 1:
		flags = 22
		break
	if b % 2 == 0:
		bb[0] += 1
		b //= 2
		flags = 1
	elif b % 3 == 0:
		bb[1] += 1
		b //= 3
		flags = 1
	elif b % 5 == 0:
		bb[2] += 1
		b //= 5
		flags = 1
	if flags == 0:
		flags = 33
		break
if p == q:
	print(0)
elif a == b:
	print(max(aa[0], bb[0]) - min(aa[0], bb[0]) + max(aa[1], bb[1]) - min(aa[1], bb[1]) + max(aa[2], bb[2]) - min(aa[2], bb[2]))
else:
	print(-1)


def check(n):
	c = 0
	while n % 2 == 0:
		n = n // 2
		c += 1
	while n % 3 == 0:
		n = n // 3
		c += 1
	while n % 5 == 0:
		n = n // 5
		c += 1
	if n == 1:
		return c
	else:
		return -1

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(a, b) = map(int, input().split())
k = gcd(a, b)
a = a // k
b = b // k
a1 = check(a)
a2 = check(b)
if a1 < 0 or a2 < 0:
	print(-1)
else:
	print(a1 + a2)


import math

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while a % b != 0:
		(a, b) = (b, a % b)
	return b
(a, b) = map(int, input().split())
res = 0
for i in [2, 3, 5]:
	r = 0
	while a % i == 0:
		a //= i
		r += 1
	while b % i == 0:
		b //= i
		r -= 1
	res += abs(r)
if gcd(a, b) == 1 and a != b:
	print(-1)
else:
	print(res)


d = {}

def solve(a, b):
	if a > b:
		(a, b) = (b, a)
	if a == b:
		return 0
	args = [(a % 2, (a // 2, b)), (a % 3, (a // 3, b)), (a % 5, (a // 5, b)), (b % 2, (a, b // 2)), (b % 3, (a, b // 3)), (b % 5, (a, b // 5))]
	res = []
	for (cond, (arg1, arg2)) in args:
		if not cond:
			tmp = d.get((arg1, arg2))
			if tmp is None:
				tmp = solve(arg1, arg2)
				d[arg1, arg2] = tmp
			if tmp != -1:
				res.append(tmp + 1)
	if res:
		return min(res)
	else:
		return -1
(a, b) = map(int, input().split())
print(solve(a, b))


import math

def main():
	(a, b) = map(int, input().split())
	d = math.gcd(a, b)
	r1 = a // d
	r2 = b // d
	count = 0
	for i in [2, 3, 5]:
		while r1 % i == 0:
			r1 = r1 // i
			count += 1
		while r2 % i == 0:
			r2 = r2 // i
			count += 1
	if r1 != 1 or r2 != 1:
		print(-1)
	else:
		print(count)
main()


import math

def prime_factors(n):
	global arr
	while n % 2 == 0:
		arr.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			arr.append(i)
			n = n // i
	if n > 2:
		arr.append(n)
(a, b) = list(map(int, input().split()))
a1 = 0
a2 = 0
b1 = 0
b2 = 0
c1 = 0
c2 = 0
if a == b:
	print(0)
	exit()
arr = []
prime_factors(a)
s1 = len(arr)
if 2 in arr:
	a1 = arr.count(2)
if 3 in arr:
	b1 = arr.count(3)
if 5 in arr:
	c1 = arr.count(5)
arr = map(str, arr)
wonder1 = ''.join(arr)
wonder1 = wonder1.replace('2', '')
wonder1 = wonder1.replace('3', '')
wonder1 = wonder1.replace('5', '')
wonder1 = list(wonder1)
arr = []
prime_factors(b)
s2 = len(arr)
if 2 in arr:
	a2 = arr.count(2)
if 3 in arr:
	b2 = arr.count(3)
if 5 in arr:
	c2 = arr.count(5)
arr = map(str, arr)
wonder2 = ''.join(arr)
wonder2 = wonder2.replace('2', '')
wonder2 = wonder2.replace('3', '')
wonder2 = wonder2.replace('5', '')
wonder2 = list(wonder2)
if wonder1 == wonder2:
	print(abs(a1 - a2) + abs(b2 - b1) + abs(c2 - c1))
else:
	print(-1)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'
mod = 10 ** 9 + 7

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def ispali(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	(a, b) = mi()
	d1 = [0] * 6
	d2 = [0] * 6
	for i in [2, 3, 5]:
		if a % i == 0:
			while a % i == 0:
				d1[i] += 1
				a //= i
		if b % i == 0:
			while b % i == 0:
				d2[i] += 1
				b //= i
	cnt = 0
	if a == b:
		for i in [2, 3, 5]:
			x = min(d1[i], d2[i])
			cnt += max(d1[i], d2[i]) - x
	else:
		cnt = -1
	print(cnt)
main()


def cal(a, b):
	ans = 0
	while 1 > 0:
		if a % b == 0:
			a = a // b
			ans += 1
		else:
			break
	return ans
(a, b) = map(int, input().split())
ans = 0
for i in [2, 3, 5]:
	ta = cal(a, i)
	tb = cal(b, i)
	ans += abs(ta - tb)
	if ta > tb:
		a = a // pow(i, ta - tb)
	else:
		b = b // pow(i, tb - ta)
if a != b:
	print(-1)
else:
	print(ans)


from sys import stdin
from collections import defaultdict
import sys
sys.setrecursionlimit(15000)

def factors(num, arr):
	count = 0
	while num % 2 == 0:
		num //= 2
		count += 1
	arr.append(count)
	count = 0
	while num % 3 == 0:
		num //= 3
		count += 1
	arr.append(count)
	count = 0
	while num % 5 == 0:
		num //= 5
		count += 1
	arr.append(count)
	arr.append(num)
(a, b) = list(map(int, stdin.readline().split()))
A = []
B = []
factors(a, A)
factors(b, B)
if A[3] == B[3]:
	print(abs(A[0] - B[0]) + abs(A[1] - B[1]) + abs(A[2] - B[2]))
else:
	print(-1)


(a, b) = map(int, input().split())
if a == b:
	print(0)
else:
	a2 = 0
	a3 = 0
	a5 = 0
	while True:
		if a % 2 == 0:
			a2 += 1
			a = a // 2
		elif a % 3 == 0:
			a3 += 1
			a = a // 3
		elif a % 5 == 0:
			a5 += 1
			a = a // 5
		else:
			break
	b2 = 0
	b3 = 0
	b5 = 0
	while True:
		if b % 2 == 0:
			b2 += 1
			b = b // 2
		elif b % 3 == 0:
			b3 += 1
			b = b // 3
		elif b % 5 == 0:
			b5 += 1
			b = b // 5
		else:
			break
	if a != b:
		print(-1)
	else:
		print(abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5))


(n, k) = map(int, input().split())
arr = list(([0 for i in range(6)] for j in range(2)))
for i in [2, 3, 5]:
	while n % i == 0:
		n /= i
		arr[0][i] += 1
for i in [2, 3, 5]:
	while k % i == 0:
		k /= i
		arr[1][i] += 1
if n != k:
	print(-1)
	exit()
res = abs(arr[1][5] - arr[0][5])
res += abs(arr[1][3] - arr[0][3])
res += abs(arr[1][2] - arr[0][2])
print(res)


t = 1
for _ in range(t):
	inp = list(map(int, input().split()))
	(a, b) = (inp[0], inp[1])
	a2 = 0
	a3 = 0
	a5 = 0
	while a % 2 == 0:
		a2 += 1
		a = a // 2
	while a % 3 == 0:
		a3 += 1
		a = a // 3
	while a % 5 == 0:
		a5 += 1
		a = a // 5
	b2 = 0
	b3 = 0
	b5 = 0
	while b % 2 == 0:
		b2 += 1
		b = b // 2
	while b % 3 == 0:
		b3 += 1
		b = b // 3
	while b % 5 == 0:
		b5 += 1
		b = b // 5
	if a != b:
		print(-1)
	else:
		ans = abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5)
		print(ans)


def gcd(a, b):
	return gcd(b, a % b) if b else a
(a, b) = map(int, input().split())
k = 2 ** 30 * 3 ** 19 * 5 ** 13
(u, v) = (gcd(k, a), gcd(k, b))
if a * v != b * u:
	print(-1)
else:
	(s, c) = (0, u * v // gcd(u, v) ** 2)
	for i in [2, 3, 5]:
		while c % i == 0:
			c //= i
			s += 1
	print(s)


(a, b) = map(int, input().split())

def traverse(start, dictio, counter):
	if start in dictio and dictio[start] >= counter:
		return
	dictio[start] = counter
	if start % 5 == 0:
		traverse(start // 5, dictio, counter + 1)
	if start % 3 == 0:
		traverse(start // 3, dictio, counter + 1)
	if start % 2 == 0:
		traverse(start // 2, dictio, counter + 1)
dictA = dict()
dictB = dict()
traverse(a, dictA, 0)
traverse(b, dictB, 0)
ans = 9999999999999999
for v in dictA:
	if v in dictB:
		ans = min(ans, dictA[v] + dictB[v])
print(-1 if ans == 9999999999999999 else ans)


import sys, math, bisect
from random import randint
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
from collections import deque, defaultdict, Counter
import heapq, string
for _ in range(1):
	(a, b) = map(int, input().split())
	ans = 0
	for j in [2, 3, 5]:
		while a % j == 0 and b % j == 0:
			a = a // j
			b = b // j
		while a % j == 0:
			ans += 1
			a = a // j
		while b % j == 0:
			ans += 1
			b = b // j
	if a == b:
		print(ans)
	else:
		print(-1)


def d(q, d):
	c = 0
	while q % d == 0:
		q //= d
		c += 1
		pass
	return (c, q)
	pass

def main():
	a2 = 0
	a3 = 0
	a5 = 0
	b2 = 0
	b3 = 0
	b5 = 0
	(a, b) = map(int, input().split(' '))
	if a == b:
		print(0)
		return
		pass
	(at, bt) = (a, b)
	(a2, a) = d(a, 2)
	(a3, a) = d(a, 3)
	(a5, a) = d(a, 5)
	(b2, b) = d(b, 2)
	(b3, b) = d(b, 3)
	(b5, b) = d(b, 5)
	if a != b:
		print(-1)
		return
		pass
	print(abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5))
	pass
main()


import math

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n / i
	if n > 2:
		factors.append(int(n))
	return factors

def difference(li1, li2):
	dif = [i for i in li1 + li2 if i not in li1 or i not in li2]
	return dif
(a, b) = map(int, input().split())
l1 = primeFactors(a)
l2 = primeFactors(b)
l1_counts = [0] * 3
l2_counts = [0] * 3
for i in l1:
	if i == 2:
		l1_counts[0] += 1
	elif i == 3:
		l1_counts[1] += 1
	elif i == 5:
		l1_counts[2] += 1
for i in l2:
	if i == 2:
		l2_counts[0] += 1
	elif i == 3:
		l2_counts[1] += 1
	elif i == 5:
		l2_counts[2] += 1
x = difference(l1, l2)
for i in x:
	if i > 5:
		print(-1)
		exit(0)
answer = abs(l1_counts[0] - l2_counts[0]) + abs(l1_counts[1] - l2_counts[1]) + abs(l1_counts[2] - l2_counts[2])
print(answer)


(a, b) = list(map(int, input().split()))

def f(n):
	p = []
	for i in [2, 3, 5]:
		tot = 0
		while n % i == 0:
			tot += 1
			n //= i
		p.append((i, tot))
	p.append((n, 1))
	return p
a = f(a)
b = f(b)
if a[-1][0] != b[-1][0]:
	print(-1)
else:
	print(abs(a[0][1] - b[0][1]) + abs(a[1][1] - b[1][1]) + abs(a[2][1] - b[2][1]))


from collections import deque, Counter
from math import sqrt

def primefac(n):
	d = deque()
	while n % 2 == 0:
		n //= 2
		d.append(2)
	for j in range(3, int(sqrt(n)) + 1):
		while n % j == 0:
			n //= j
			d.append(j)
	if n > 2:
		d.append(n)
	return d
(n, m) = map(int, input().split())
if n == m:
	print(0)
	exit(0)
r1 = primefac(n)
r2 = primefac(m)
r1 = list(r1)
r2 = list(r2)
(cnt1, cnt2) = (0, 0)
flag = True
(x, y) = (Counter(r1), Counter(r2))
for i in x.keys():
	if i in y.keys() and x[i] != y[i]:
		if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
			cnt1 += abs(x[i] - y[i])
		else:
			flag = False
			break
	elif i not in y.keys():
		if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
			cnt1 += x[i]
		else:
			flag = False
			break
if flag == False:
	print(-1)
	exit(0)
for i in y.keys():
	if i not in x.keys():
		if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
			cnt2 += y[i]
		else:
			flag = False
			break
if flag == False:
	print(-1)
	exit(0)
print(cnt1 + cnt2)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def solve():
	(a, b) = map(int, input().split())
	two_a = 0
	three_a = 0
	five_a = 0
	two_b = 0
	three_b = 0
	five_b = 0
	while a % 2 == 0:
		a = a // 2
		two_a += 1
	while a % 3 == 0:
		a = a // 3
		three_a += 1
	while a % 5 == 0:
		a = a // 5
		five_a += 1
	while b % 2 == 0:
		b = b // 2
		two_b += 1
	while b % 3 == 0:
		b = b // 3
		three_b += 1
	while b % 5 == 0:
		b = b // 5
		five_b += 1
	if a != b:
		cout << -1 << endl
	else:
		cout << abs(two_a - two_b) + abs(three_a - three_b) + abs(five_a - five_b) << endl

def main():
	solve()
main()


def compute_hcf(x, y):
	if x > y:
		smaller = y
	else:
		smaller = x
	for i in range(1, smaller + 1):
		if x % i == 0 and y % i == 0:
			hcf = i
	return hcf

def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
(a, b) = map(int, input().split())
hcf = hcfnaive(a, b)
a = a / hcf
b = b / hcf
count = int(0)
while b >= 2:
	if b % 2 == 0:
		count += 1
		b = b / 2
	elif b % 3 == 0:
		count += 1
		b = b / 3
	elif b % 5 == 0:
		count += 1
		b = b / 5
	else:
		break
while a >= 2:
	if a % 2 == 0:
		count += 1
		a = a / 2
	elif a % 3 == 0:
		count += 1
		a = a / 3
	elif a % 5 == 0:
		count += 1
		a = a / 5
	else:
		break
if a != b:
	print(-1)
else:
	print(count)


from sys import stdin, stdout
input = stdin.readline

def write(n, sep='\n'):
	stdout.write(str(n))
	stdout.write(sep)

def gil():
	return list(map(int, input().split()))
(a, b) = gil()
x = [2, 3, 5]
c = 0
for i in x:
	while a % i == 0 and b % i == 0:
		a /= i
		b /= i
	while a % i == 0:
		c += 1
		a /= i
	while b % i == 0:
		c += 1
		b /= i
if a == b:
	print(c)
else:
	print(-1)


import math
(a, b) = map(int, input().split())
if a == b:
	print(0)
	exit()
g = math.gcd(a, b)
a = a // g
b = b // g
cnt = 0
while True:
	if a % 2 and a % 3 and a % 5 and b % 2 and b % 3 and b % 5:
		print(-1)
		exit()
	if b % 2 == 0:
		b = b // 2
		cnt = cnt + 1
	if b % 3 == 0:
		b = b // 3
		cnt = cnt + 1
	if b % 5 == 0:
		b = b // 5
		cnt = cnt + 1
	if a % 2 == 0:
		a = a // 2
		cnt = cnt + 1
	if a % 3 == 0:
		a = a // 3
		cnt = cnt + 1
	if a % 5 == 0:
		a = a // 5
		cnt = cnt + 1
	if a == b:
		break
print(cnt)


l = lambda : map(int, input().split())
(n, m) = l()
a = [0] * 3
b = [0] * 3
j = 0
if n == m:
	print(0)
	exit(0)
for i in [2, 3, 5]:
	while n % i == 0:
		n /= i
		a[j] += 1
	while m % i == 0:
		m /= i
		b[j] += 1
	j += 1
if n != m:
	print(-1)
else:
	print(abs(a[0] - b[0]) + abs(a[1] - b[1]) + abs(a[2] - b[2]))


import math

def find_fac_2_3_5(n):
	pow_2 = 0
	pow_3 = 0
	pow_5 = 0
	while n % 2 == 0:
		n = n // 2
		pow_2 += 1
	while n % 3 == 0:
		n = n // 3
		pow_3 += 1
	while n % 5 == 0:
		n = n // 5
		pow_5 += 1
	return (pow_2, pow_3, pow_5, n)
(a, b) = input().split(' ')
a = int(a)
b = int(b)
k = math.gcd(a, b)
(q1, q2, q3, n1) = find_fac_2_3_5(a)
(e1, e2, e3, n2) = find_fac_2_3_5(b)
if a == b:
	print('0')
elif n1 == n2:
	k = math.gcd(a // n1, b // n2)
	w1 = a // n1
	w2 = b // n2
	(x1, x2, x3, t) = find_fac_2_3_5(w1 // k)
	(y1, y2, y3, j) = find_fac_2_3_5(w2 // k)
	print(x1 + x2 + x3 + y1 + y2 + y3)
else:
	print('-1')


import math

def primeFactors(n):
	D = {2: 0, 3: 0, 5: 0}
	while n % 2 == 0:
		if 2 in D:
			D[2] += 1
		else:
			D[2] = 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			if i in D:
				D[i] += 1
			else:
				D[i] = 1
			n = n // i
	if n > 2:
		if n in D:
			D[n] += 1
		else:
			D[n] = 1
	return D
lt = list(input().split())
(a, b) = (int(lt[0]), int(lt[1]))
if a == b:
	print(0)
else:
	D1 = primeFactors(a)
	D2 = primeFactors(b)
	a = b = 1
	for i in D1:
		if i not in [2, 3, 5]:
			a *= i ** D1[i]
	for i in D2:
		if i not in [2, 3, 5]:
			b *= i ** D2[i]
	if a != b:
		print(-1)
	else:
		print(abs(D1[2] - D2[2]) + abs(D1[3] - D2[3]) + abs(D1[5] - D2[5]))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

def in_list():
	return list(map(int, input().split()))

def in_str():
	s = input()
	return list(s[:len(s) - 1])

def in_ints():
	return map(int, input().split())
(a, b) = in_ints()
count2 = 0
count3 = 0
count5 = 0
while a % 2 == 0:
	a = a // 2
	count2 += 1
while a % 3 == 0:
	a = a // 3
	count3 += 1
while a % 5 == 0:
	a = a // 5
	count5 += 1
while b % 2 == 0:
	b = b // 2
	count2 -= 1
while b % 3 == 0:
	b = b // 3
	count3 -= 1
while b % 5 == 0:
	b = b // 5
	count5 -= 1
if b == a:
	ans = abs(count2) + abs(count3) + abs(count5)
	print(ans)
else:
	print(-1)


(a, b) = map(int, input().split())
a_d = [0] * 4
b_d = [0] * 4
div = 2
while div <= 5:
	if div == 4:
		div += 1
		continue
	if a % div == 0:
		a_d[div - 2] += 1
		a //= div
	else:
		div += 1
div = 2
while div <= 5:
	if div == 4:
		div += 1
		continue
	if b % div == 0:
		b_d[div - 2] += 1
		b //= div
	else:
		div += 1
if a != b:
	print(-1)
else:
	print(sum((abs(a_d[i] - b_d[i]) for i in range(4))))


import math
(a, b) = map(int, input().split())
q = math.gcd(a, b)
a = a // q
b = b // q
p = a * b
c = 0
while p % 2 == 0:
	c = c + 1
	p = p // 2
while p % 3 == 0:
	c = c + 1
	p = p // 3
while p % 5 == 0:
	c += 1
	p = p // 5
if p == 1:
	print(c)
else:
	print(-1)


from sys import stdin, stdout
input = stdin.readline
import math, bisect

def gcd(a, b):
	if a == 0:
		return b
	if b == 0:
		return a
	return gcd(b, a % b)
(a, b) = map(int, input().split())
g = gcd(a, b)
a1 = a // g
b1 = b // g
f = 0
ans = 0
while a1:
	if a1 % 2 == 0:
		a1 = a1 // 2
		ans += 1
	elif a1 % 3 == 0:
		a1 = a1 // 3
		ans += 1
	elif a1 % 5 == 0:
		a1 = a1 // 5
		ans += 1
	else:
		break
while b1:
	if b1 % 2 == 0:
		b1 = b1 // 2
		ans += 1
	elif b1 % 3 == 0:
		b1 = b1 // 3
		ans += 1
	elif b1 % 5 == 0:
		b1 = b1 // 5
		ans += 1
	else:
		break
if a1 != 1 or b1 != 1:
	print(-1)
else:
	print(ans)


(a, b) = map(int, input().split())
res = 0
for x in (2, 3, 5):
	while a % x == 0 and b % x == 0:
		a //= x
		b //= x
	while a % x == 0:
		a //= x
		res += 1
	while b % x == 0:
		b //= x
		res += 1
if a == b:
	print(res)
else:
	print(-1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(ele, end='\n')
(n, m) = L()
A = [0 for i in range(6)]
B = [0 for i in range(6)]
for divs in [2, 3, 5]:
	while n % divs == 0:
		A[divs] += 1
		n //= divs
	while m % divs == 0:
		B[divs] += 1
		m //= divs
if n != m:
	print(-1)
else:
	ans = 0
	for i in range(6):
		ans += abs(A[i] - B[i])
	print(ans)
endtime = time.time()


(a, b) = input().strip().split(' ')
(a, b) = [int(a), int(b)]
cnt1 = 0
cn2 = 0
cnt2 = 0
cn3 = 0
cnt3 = 0
cn4 = 0
while a % 2 == 0:
	a /= 2
	cnt1 += 1
while a % 3 == 0:
	a /= 3
	cnt2 += 1
while a % 5 == 0:
	a /= 5
	cnt3 += 1
while b % 2 == 0:
	b /= 2
	cn2 += 1
while b % 3 == 0:
	b /= 3
	cn3 += 1
while b % 5 == 0:
	b /= 5
	cn4 += 1
if a == b:
	print(abs(cnt1 - cn2) + abs(cnt2 - cn3) + abs(cnt3 - cn4))
else:
	print(-1)


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def main():
	(x, y) = map(int, input().split(' '))
	eq = gcd(x, y)
	(a, b) = (int(x / eq), int(y / eq))
	ans = 0
	while True:
		if a % 2 == 0:
			a = int(a / 2)
			ans += 1
		if a % 3 == 0:
			a = int(a / 3)
			ans += 1
		if a % 5 == 0:
			a = int(a / 5)
			ans += 1
		if a % 2 != 0 and a % 3 != 0 and (a % 5 != 0):
			if a != 1:
				print(-1)
				exit()
			if a == 1:
				break
	while True:
		if b % 2 == 0:
			b = int(b / 2)
			ans += 1
		if b % 3 == 0:
			b = int(b / 3)
			ans += 1
		if b % 5 == 0:
			b = int(b / 5)
			ans += 1
		if b % 2 != 0 and b % 3 != 0 and (b % 5 != 0):
			if b != 1:
				print(-1)
				exit()
			if b == 1:
				break
	print(ans)
main()


import sys
sys.setrecursionlimit(100000)
(n, m) = [int(x) for x in sys.stdin.readline().strip().split()]

def factors(n):
	d = {2: 0, 3: 0, 5: 0}
	arr = [2, 3, 5]
	for i in arr:
		s = n
		while s:
			if s % i == 0:
				d[i] += 1
			s = s / i
	return d
n_fac = factors(n)
m_fac = factors(m)
comm_fac = {2: min(n_fac[2], m_fac[2]), 3: min(n_fac[3], m_fac[3]), 5: min(n_fac[5], m_fac[5])}
nd = 2 ** (n_fac[2] - comm_fac[2]) * 3 ** (n_fac[3] - comm_fac[3]) * 5 ** (n_fac[5] - comm_fac[5])
md = 2 ** (m_fac[2] - comm_fac[2]) * 3 ** (m_fac[3] - comm_fac[3]) * 5 ** (m_fac[5] - comm_fac[5])
if n / nd == m / md:
	nc = n_fac[2] + n_fac[3] + n_fac[5]
	mc = m_fac[2] + m_fac[3] + m_fac[5]
	cc = comm_fac[2] + comm_fac[3] + comm_fac[5]
	c = 2 * cc - nc - mc
	print(-c)
else:
	print(-1)


def cheese(a, b):
	if a == b:
		return 0
	(a1, b1) = (a, b)
	while a1 > 0:
		if a1 < b1:
			a1 += b1
			b1 = a1 - b1
			a1 = a1 - b1
		a1 %= b1
	a //= b1
	b //= b1
	result = 0
	while a % 2 == 0:
		a //= 2
		result += 1
	while a % 3 == 0:
		a //= 3
		result += 1
	while a % 5 == 0:
		a //= 5
		result += 1
	while b % 2 == 0:
		b //= 2
		result += 1
	while b % 3 == 0:
		b //= 3
		result += 1
	while b % 5 == 0:
		b //= 5
		result += 1
	if a == 1 and b == 1:
		return result
	return -1
(A, B) = [int(i) for i in input().split()]
print(cheese(A, B))


def gcd(a, b):
	while b != 0:
		a %= b
		t = a
		a = b
		b = t
	return a

def main():
	(a, b) = list(map(int, input().split(' ')))
	gg = gcd(a, b)
	ans = 0
	can = 1
	A = []
	A.append(a / gg)
	A.append(b / gg)
	for g in A:
		while g != 1:
			ok = 0
			if g % 2 == 0:
				g = g / 2
				ok = 1
				ans = ans + 1
			if g % 3 == 0:
				g = g / 3
				ok = 1
				ans = ans + 1
			if g % 5 == 0:
				g = g / 5
				ok = 1
				ans = ans + 1
			if ok == 0:
				can = 0
				break
	if can == 0:
		print('-1')
	else:
		print(ans)

def __starting_point():
	main()
__starting_point()


def dividir(a, b):
	if a == b:
		return 0
	divisores = [2, 3, 5]
	cont = 0
	for i in divisores:
		while a % i == 0 and b % i == 0:
			a = a / i
			b = b / i
		while a % i == 0:
			a = a / i
			cont += 1
		while b % i == 0:
			b = b / i
			cont += 1
	if a != b:
		return -1
	else:
		return cont
gramos = input()
gramos = gramos.split()
a = int(gramos[0])
b = int(gramos[1])
print(dividir(a, b))


def gcd(a, b):
	c = max(a, b)
	d = min(a, b)
	if d == 0:
		return a
	else:
		return gcd(d, c % d)
ab = list(input().split())
a = int(ab[0])
b = int(ab[1])
s = gcd(a, b)
a = a // s
b = b // s
h = 0
while a != 1:
	if a % 2 == 0:
		h = h + 1
		a = a // 2
	elif a % 3 == 0:
		h = h + 1
		a = a // 3
	elif a % 5 == 0:
		h = h + 1
		a = a // 5
	else:
		break
while b != 1:
	if b % 2 == 0:
		h = h + 1
		b = b // 2
	elif b % 3 == 0:
		h = h + 1
		b = b // 3
	elif b % 5 == 0:
		h = h + 1
		b = b // 5
	else:
		break
if a != b:
	print(-1)
else:
	print(h)


(a, b) = [int(i) for i in input().split()]
done = 0
count = 0
a2 = a3 = a5 = b2 = b3 = b5 = 0
if a == b:
	print(0)
else:
	while True:
		if a % 2 == 0:
			a /= 2
			a2 += 1
		elif a % 3 == 0:
			a /= 3
			a3 += 1
		elif a % 5 == 0:
			a /= 5
			a5 += 1
		else:
			break
	while True:
		if b % 2 == 0:
			b /= 2
			b2 += 1
		elif b % 3 == 0:
			b /= 3
			b3 += 1
		elif b % 5 == 0:
			b /= 5
			b5 += 1
		else:
			break
	if a == b:
		print(abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5))
	else:
		print(-1)


(a, b) = map(int, input().split())
(b_2, b_3, b_5) = (0, 0, 0)
(a_2, a_3, a_5) = (0, 0, 0)
while b % 2 == 0:
	b_2 += 1
	b //= 2
while b % 3 == 0:
	b_3 += 1
	b //= 3
while b % 5 == 0:
	b_5 += 1
	b //= 5
while a % 2 == 0:
	a_2 += 1
	a //= 2
while a % 3 == 0:
	a_3 += 1
	a //= 3
while a % 5 == 0:
	a_5 += 1
	a //= 5
if a != b:
	print(-1)
else:
	print(abs(a_2 - b_2) + abs(a_3 - b_3) + abs(a_5 - b_5))


from collections import Counter

def solve(n):
	t = []
	while n % 2 == 0:
		t.append(2)
		n //= 2
	i = 3
	while i * i <= n:
		while n % i == 0:
			t.append(i)
			n //= i
		i += 1
	if n > 2:
		t.append(n)
	return t
(a, b) = map(int, input().split())
if a == b:
	print(0)
	exit()
r1 = Counter(solve(a))
r2 = Counter(solve(b))
(cnt1, cnt2) = (0, 0)
flag = True
for i in r1.keys():
	if i in r2.keys() and r1[i] != r2[i]:
		if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
			cnt1 += abs(r1[i] - r2[i])
		else:
			flag = False
			break
	elif i not in r2.keys():
		if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
			cnt1 += r1[i]
		else:
			flag = False
			break
if flag == False:
	print('-1')
	exit(0)
for i in r2.keys():
	if i not in r1.keys():
		if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
			cnt2 += r2[i]
		else:
			flag = False
			break
if flag == False:
	print(-1)
	exit(0)
print(cnt1 + cnt2)


import sys
input = sys.stdin.readline
import math

def primefactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n // i
	if n > 2:
		l.append(n)
	return l
(a, b) = map(int, input().split())
z1 = primefactors(a)
z2 = primefactors(b)
r1 = {}
r2 = {}
for i in z1:
	if i in r1:
		r1[i] += 1
	else:
		r1[i] = 1
for i in z2:
	if i in r2:
		r2[i] += 1
	else:
		r2[i] = 1
o = [2, 3, 5]
ans = 0
for i in range(2, 6):
	if i == 4:
		continue
	else:
		e1 = 0
		e2 = 0
		if i in r1:
			e1 = r1[i]
		if i in r2:
			e2 = r2[i]
		ans += abs(e2 - e1)
flag = 0
for i in r1:
	if i != 2 and i != 3 and (i != 5):
		if i in r2:
			if r2[i] != r1[i]:
				flag = 1
				break
		else:
			flag = 1
			break
for i in r2:
	if i != 2 and i != 3 and (i != 5):
		if i in r1:
			if r2[i] != r1[i]:
				flag = 1
				break
		else:
			flag = 1
			break
if flag:
	print(-1)
else:
	print(ans)


(a, b) = list(map(int, input().split()))
(rema, remb) = (a, b)
(cnta, cntb) = ({}, {})
for i in [2, 3, 5]:
	cnta[i] = 0
	cntb[i] = 0
	while rema % i == 0:
		rema = rema // i
		cnta[i] += 1
	while remb % i == 0:
		remb = remb // i
		cntb[i] += 1
if rema == remb:
	ans = 0
	for i in [2, 3, 5]:
		ans += abs(cnta[i] - cntb[i])
	print(ans)
else:
	print(-1)


def inp():
	return map(int, input().split())
c = 0

def divide(x):
	if x == 1:
		return
	if x % 2 == 0:
		divide(x // 2)
	elif x % 3 == 0:
		divide(x // 3)
	elif x % 5 == 0:
		divide(x // 5)
	else:
		exit(print(-1))
	global c
	c += 1
from math import *
(a, b) = inp()
g = gcd(a, b)
if a == b:
	print(0)
else:
	divide(a // g)
	divide(b // g)
	print(c)


(a, b) = map(int, input().split())
x1 = 0
for i in (2, 3, 5):
	while a % i == 0 and b % i == 0:
		a = a / i
		b /= i
	while a % i == 0:
		a = a / i
		x1 = x1 + 1
	while b % i == 0:
		b = b / i
		x1 = x1 + 1
if a == b:
	print(x1)
else:
	print(-1)


import math
(n, m) = map(int, input().split())
s = math.gcd(n, m)
n = n // s
m = m // s
a = [2, 3, 5]
i = 0
r = 0
while i != 3:
	if n % a[i] == 0:
		n = n // a[i]
		r += 1
	else:
		i += 1
i = 0
while i != 3:
	if m % a[i] == 0:
		m = m // a[i]
		r += 1
	else:
		i += 1
if n == m == 1:
	print(r)
else:
	print(-1)


(a, b) = map(int, input().split())
div = [2, 3, 5]
op = 0
if 1 <= a <= 10000000000.0 and 1 <= b <= 10000000000.0:
	if a == b:
		print(op)
	else:
		for i in div:
			while a % i == 0 and b % i == 0:
				a = a / i
				b = b / i
			while a % i == 0:
				a = a / i
				op += 1
			while b % i == 0:
				b = b / i
				op += 1
		if a == b:
			print(op)
		else:
			print(-1)
else:
	print('Error')


from math import *
b = input()
b = b.split()
n = int(b[0])
m = int(b[1])
b = [2, 3, 5]
a = []
c = []
for x in range(10):
	a.append(0)
	c.append(0)
for x in b:
	l = n
	while l % x == 0:
		a[x] += 1
		l /= x
	l = m
	while l % x == 0:
		c[x] += 1
		l /= x
ans = 0
for x in b:
	if a[x] != c[x]:
		l = abs(a[x] - c[x])
		ans += l
		if a[x] < c[x]:
			for y in range(l):
				m /= x
		else:
			for y in range(l):
				n /= x
if n == m:
	print(ans)
else:
	print(-1)


def primeFactorize(n):
	factors = [1]
	div = 2
	while n > 1:
		while n % div == 0:
			factors.append(div)
			n //= div
		div += 1
	return factors
(a, b) = [int(x) for x in input().split()]
(a2, a3, a5) = (0, 0, 0)
(b2, b3, b5) = (0, 0, 0)
while a % 2 == 0:
	a2 += 1
	a //= 2
while a % 3 == 0:
	a3 += 1
	a //= 3
while a % 5 == 0:
	a5 += 1
	a //= 5
while b % 2 == 0:
	b2 += 1
	b //= 2
while b % 3 == 0:
	b3 += 1
	b //= 3
while b % 5 == 0:
	b5 += 1
	b //= 5
if a != b:
	ans = -1
else:
	ans = abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5)
print(ans)


import math
import sys
from collections import defaultdict, Counter, deque
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
dp = []
(N1, N2) = ilele()
if N1 == N2:
	print(0)
else:
	(a, b, c, d, e, f) = (0, 0, 0, 0, 0, 0)
	while N1 > 0 and N1 % 2 == 0:
		a += 1
		N1 //= 2
	while N1 > 0 and N1 % 3 == 0:
		b += 1
		N1 //= 3
	while N1 > 0 and N1 % 5 == 0:
		c += 1
		N1 //= 5
	while N2 > 0 and N2 % 2 == 0:
		d += 1
		N2 //= 2
	while N2 > 0 and N2 % 3 == 0:
		e += 1
		N2 //= 3
	while N2 > 0 and N2 % 5 == 0:
		f += 1
		N2 //= 5
	if N1 != N2:
		print(-1)
	else:
		print(abs(a - d) + abs(b - e) + abs(c - f))


import math
from collections import Counter

def primeFactors(n):
	a = []
	while n % 2 == 0:
		a.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			a.append(i)
			n = n // i
	if n > 2:
		a.append(n)
	return a
(a, b) = list(map(int, input().split()))
hcf = math.gcd(a, b)
if a == b:
	print(0)
else:
	a //= hcf
	b //= hcf
	a = Counter(primeFactors(a))
	b = Counter(primeFactors(b))
	output = 0
	f = 0
	for i in a:
		if i in [2, 3, 5]:
			output += a[i]
		else:
			f = 1
			break
	if f == 0:
		for i in b:
			if i in [2, 3, 5]:
				output += b[i]
			else:
				f = 1
				break
	if f == 1:
		print(-1)
	else:
		print(output)


def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors
(a, b) = map(int, input().split())
factor_a = prime_factors(a)
factor_b = prime_factors(b)
(freq_factor_a, freq_factor_b) = (dict(), dict())
freq_factor_a[2] = freq_factor_a[3] = freq_factor_a[5] = 0
freq_factor_b[2] = freq_factor_b[3] = freq_factor_b[5] = 0
for e in factor_a:
	if e in freq_factor_a:
		freq_factor_a[e] += 1
	else:
		freq_factor_a[e] = 1
for e in factor_b:
	if e in freq_factor_b:
		freq_factor_b[e] += 1
	else:
		freq_factor_b[e] = 1
no_solution = False
res = 0
possible_factors = list(set(freq_factor_a.keys()) | set(freq_factor_b.keys()))
for possible_factor in possible_factors:
	if possible_factor in freq_factor_a and possible_factor not in freq_factor_b or (possible_factor in freq_factor_b and possible_factor not in freq_factor_a):
		no_solution = True
		break
	elif possible_factor in [2, 3, 5]:
		res += abs(freq_factor_a[possible_factor] - freq_factor_b[possible_factor])
	elif freq_factor_a[possible_factor] != freq_factor_b[possible_factor]:
		no_solution = True
		break
print(-1 if no_solution else res)


def fun(x):
	(a, b, c) = (0, 0, 0)
	while x % 2 == 0:
		x = int(x / 2)
		a += 1
	while x % 3 == 0:
		x = int(x / 3)
		b += 1
	while x % 5 == 0:
		x = int(x / 5)
		c += 1
	p = [x, a, b, c]
	return p
(x, y) = map(int, input().split())
if x == y:
	print(0)
elif fun(x)[0] != fun(y)[0]:
	print(-1)
else:
	print(abs(fun(x)[1] - fun(y)[1]) + abs(fun(x)[2] - fun(y)[2]) + abs(fun(x)[3] - fun(y)[3]))


(a, b) = map(int, input().split())
c = [2, 3, 5]
r = 0
for i in c:
	x = 0
	y = 0
	while a % i == 0:
		x += 1
		a //= i
	while b % i == 0:
		y += 1
		b //= i
	r += max(x, y) - min(x, y)
if a == b:
	print(r)
else:
	print(-1)


(a, b) = map(int, input().split())
k = a
l = b
(a2, a3, a5) = (0, 0, 0)
(b2, b3, b5) = (0, 0, 0)
while k:
	if k % 2 == 0:
		a2 += 1
		k = k / 2
	elif k % 3 == 0:
		a3 += 1
		k = k / 3
	elif k % 5 == 0:
		a5 += 1
		k = k / 5
	else:
		break
while l:
	if l % 2 == 0:
		b2 += 1
		l = l / 2
	elif l % 3 == 0:
		b3 += 1
		l = l / 3
	elif l % 5 == 0:
		b5 += 1
		l = l / 5
	else:
		break
if k != l:
	print(-1)
else:
	print(max(a2, b2) - min(a2, b2) + max(a3, b3) - min(a3, b3) + max(a5, b5) - min(a5, b5))


(a, b) = list(map(int, input().split()))
if a == b:
	print(0)
else:
	d1 = {2: 0, 3: 0, 5: 0}
	d2 = {2: 0, 3: 0, 5: 0}
	f1 = 0
	f2 = 0
	while a > 1:
		if a % 2 == 0:
			a = a // 2
			d1[2] += 1
		elif a % 3 == 0:
			a = a // 3
			d1[3] += 1
		elif a % 5 == 0:
			a = a // 5
			d1[5] += 1
		else:
			f1 = 1
			break
	while b > 1:
		if b % 2 == 0:
			b = b // 2
			d2[2] += 1
		elif b % 3 == 0:
			b = b // 3
			d2[3] += 1
		elif b % 5 == 0:
			b = b // 5
			d2[5] += 1
		else:
			f2 = 1
			break
	if a != b:
		print(-1)
	else:
		t1 = 0
		if d1[2] != d2[2]:
			t1 += abs(d1[2] - d2[2])
		if d1[3] != d2[3]:
			t1 += abs(d2[3] - d1[3])
		if d1[5] != d2[5]:
			t1 += abs(d2[5] - d1[5])
		print(t1)


def primfacs(n):
	i = 2
	primfac = []
	while i * i <= n:
		while n % i == 0:
			primfac.append(i)
			n = n // i
		i = i + 1
	if n > 1:
		primfac.append(n)
	return primfac
(n, m) = map(int, input().split())
if n == m:
	print(0)
	exit()
(nn, mm) = (primfacs(n), primfacs(m))
(a, b) = (set(nn), set(mm))
c = a ^ b
if not c <= {2, 3, 5}:
	print(-1)
	exit()
ans = 0
for i in [2, 3, 5]:
	ans += abs(nn.count(i) - mm.count(i))
print(ans)


import math
import sys

def main():
	(a, b) = map(int, input().split())
	(two_a, two_b, three_a, three_b, five_a, five_b) = (0, 0, 0, 0, 0, 0)
	while a % 2 == 0:
		two_a += 1
		a /= 2
	while a % 3 == 0:
		three_a += 1
		a /= 3
	while a % 5 == 0:
		five_a += 1
		a /= 5
	while b % 2 == 0:
		two_b += 1
		b /= 2
	while b % 3 == 0:
		three_b += 1
		b /= 3
	while b % 5 == 0:
		five_b += 1
		b /= 5
	if a != b:
		print(-1)
	else:
		print(abs(two_a - two_b) + abs(three_a - three_b) + abs(five_a - five_b))
main()


(a, b) = map(int, input().split())
div_a = [0, 0, 0]
div_b = [0, 0, 0]
div = [2, 3, 5]
if a != b:
	for (i, d) in enumerate(div):
		while a % d == 0:
			div_a[i] += 1
			a /= d
	for (i, d) in enumerate(div):
		while b % d == 0:
			div_b[i] += 1
			b /= d
	if a != b:
		print(-1)
	else:
		res = 0
		for i in range(3):
			res += abs(div_a[i] - div_b[i])
		print(res)
else:
	print(0)


from math import gcd

def factorize(n):
	count = [0, 0, 0]
	while n != 1:
		if n & 1 == 0:
			count[0] += 1
			n //= 2
		elif n % 3 == 0:
			count[1] += 1
			n //= 3
		elif n % 5 == 0:
			n //= 5
			count[2] += 1
		else:
			break
	return (count, n)

def diff(x, y):
	total = 0
	for (a, b) in zip(x, y):
		total += abs(a - b)
	return total

def main():
	(a, b) = map(int, input().split(' '))
	if a == b:
		return 0
	(x, rem1) = factorize(a)
	(y, rem2) = factorize(b)
	if rem1 != rem2:
		return -1
	else:
		return diff(x, y)
print(main())