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

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))


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)


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))


(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))


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)


(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))


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]))


(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))


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))


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))


(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()


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)


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))


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)


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()


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()


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())