Polycarp plays "Game 23". Initially he has a number $n$ and his goal is to transform it to $m$. In one move, he can multiply $n$ by $2$ or multiply $n$ by $3$. He can perform any number of moves.

Print the number of moves needed to transform $n$ to $m$. Print -1 if it is impossible to do so.

It is easy to prove that any way to transform $n$ to $m$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).


-----Input-----

The only line of the input contains two integers $n$ and $m$ ($1 \le n \le m \le 5\cdot10^8$).


-----Output-----

Print the number of moves to transform $n$ to $m$, or -1 if there is no solution.


-----Examples-----
Input
120 51840

Output
7

Input
42 42

Output
0

Input
48 72

Output
-1



-----Note-----

In the first example, the possible sequence of moves is: $120 \rightarrow 240 \rightarrow 720 \rightarrow 1440 \rightarrow 4320 \rightarrow 12960 \rightarrow 25920 \rightarrow 51840.$ The are $7$ steps in total.

In the second example, no moves are needed. Thus, the answer is $0$.

In the third example, it is impossible to transform $48$ to $72$.

Difficulty: introductory

Starter code:

Solutions:
n, m = map(int, input().split())
if m % n == 0:
    k = m // n
    res = 0
    while k % 2 == 0:
        k //= 2
        res += 1
    while k % 3 == 0:
        k //= 3
        res += 1
    if k > 1:
        print(-1)
    else:
        print(res)
else:
    print(-1)

n, m = map(int, input().split())
if m % n:
    print(-1)
    return
m //= n
a = 0
while m % 2 == 0:
    m//=2
    a+=1
while m % 3 == 0:
    m//=3
    a+=1
if m==1:
    print(a)
else:
    print(-1)

def func(a,b):
  if b%a!=0:
    return -1
  else:
    store=b//a
    count=0
    while store%2==0:
      store//=2
      count+=1
    while store%3==0:
      store//=3
      count+=1
    if store==1:
      return count
    else:
      return -1
def main():
  arr=input().split()
  print(func(int(arr[0]),int(arr[1])))
main()


n, m = list(map(int, input().split()))
if m % n != 0:
    print(-1)
else:
    x = m // n
    ans = 0
    while x % 2 == 0:
        ans += 1
        x //= 2
    while x % 3 == 0:
        ans += 1
        x //= 3
    if x != 1:
        print(-1)
    else:
        print(ans)


#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)

isdebug = False
try :
    #raise ModuleNotFoundError
    import pylint
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
    isdebug = True
except Exception:
    def dprint(*args, **kwargs):
        pass


def red_inout():
    inId = 0
    outId = 0
    if not isdebug:
        inId = 0
        outId = 0
    if inId>0:
        dprint('use input', inId)
        try:
            f = open('input'+ str(inId) + '.txt', 'r')
            sys.stdin = f #标准输出重定向至文件
        except Exception:
            dprint('invalid input file')
    if outId>0:
        dprint('use output', outId)
        try:
            f = open('stdout'+ str(outId) + '.txt', 'w')
            sys.stdout = f #标准输出重定向至文件
        except Exception:
            dprint('invalid output file')
            
        atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit

if isdebug and len(sys.argv) == 1:
    red_inout()

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

def solve(): 
    pass
    
T_ = 1    
#T_, = getIntList()

for iii_ in range(T_):
    #solve()
    N, M  = getIntList()
    r = 0
    if M%N!=0:
        print(-1)
        break
    a = M//N
    while a%2==0:
        r+=1
        a//=2
    while a%3==0:
        r+=1
        a//=3
    if a!=1:
        print(-1)
    else:
        print(r)



N,M=list(map(int,input().split()))
d = M/N
if not d.is_integer():
    print(-1)
else:
    d = int(d)
    n = 0
    while d and d%2==0:
        n += 1
        d >>= 1
    while d and d%3==0:
        n += 1
        d //= 3
    if d == 1:
        print(n)
    else:
        print(-1)


from math import sqrt


def factor(n):
    potentional_p = 3
    itog_list = []
    while n % 2 == 0:
        n = n // 2
        itog_list.append(2)
    while n - 1:
        if potentional_p > sqrt(n):
            itog_list.append(n)
            return itog_list
        while n % potentional_p == 0:
            n = n // potentional_p
            itog_list.append(potentional_p)
        potentional_p += 2
    return itog_list


n, m = map(int, input().split())
if m % n != 0:
    print(-1)
    return
z = m // n
F = factor(z)
if F == []:
    print(0)
    return
if (len(set(F)) == 2 and 2 in F and 3 in F) or (len(set(F)) == 1 and (2 in F or 3 in F)):\
    print(len(F))
else:
    print(-1)

n, m = (list(map(int, input().split())))
if m % n != 0:
  print(-1)
else:
  m //= n
  t = 0
  while m % 2 == 0:
    m //= 2
    t += 1
  while m % 3 == 0:
    t += 1
    m //= 3
  print(t if m == 1 else -1)


import sys
n, m = list(map(int,input().split()))
if (m%n):
	print(-1)
	return
u = m//n;
cnt = 0;
while (u % 2 == 0):
	u //=2
	cnt += 1
while (u % 3 == 0):
	u //=3
	cnt += 1
print(cnt if u == 1 else -1)


n, m = list(map(int, input().split()))

if m % n > 0:
    print(-1)
else:
    res = 0
    a = m // n;
    while a % 2 == 0:
        a //= 2
        res += 1
    while a % 3 == 0:
        a //= 3
        res += 1
    if a == 1:
        print(res)
    else:
        print(-1)


def fact(k):
    a, b = 0, 0
    while k % 2 == 0:
        k //= 2
        a += 1
    while k % 3 == 0:
        k //= 3
        b += 1
    if k != 1:
        return -1
    return a + b


n, m = list(map(int, input().split()))
if n > m or m / n != m // n:
    print(-1)
elif n == m:
    print(0)
else:
    print(fact(m // n))


n, m = map(int, input().split())

total = 0

if m%n!=0:
	print(-1)
	return

v = m//n

while v%2==0:
	total += 1
	v //= 2
while v%3==0:
	total += 1
	v //= 3
if v!=1:
	print(-1)
	return
print(total)

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

n, m = mp()
if m % n != 0:
    print(-1)
else:
    c = 0
    k = m // n
    while k % 2 == 0:
        k //= 2
        c += 1
    while k % 3 == 0:
        k //= 3
        c += 1
    if k == 1:
        print(c)
    else:
        print(-1)

n,m = list(map(int,input().split()))
num = m / n
flag = 1
ans = 0
while num > 1:
    if num % 2 == 0:
        num //= 2
        ans += 1
        continue
    if num % 3 == 0:
        num //= 3
        ans += 1
        continue
    flag = 0
    break
if flag:
    print(ans)
else:
    print(-1)


n, m = map(int, input().split())
x = m // n
if n * x < m:
    print(-1)
else:
    k = 0
    while x % 3 == 0:
        x = x//3
        k += 1
    while x % 2 == 0:
        x = x // 2
        k += 1
    if x != 1:
        print(-1)
    else:
        print(k)

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
if m % n == 0:
    d = m // n
    c2 = c3 = 0
    while d % 2 == 0:
        c2 += 1
        d //= 2
    while d % 3 == 0:
        c3 += 1
        d //= 3
    print(c2 + c3 if d == 1 else -1)
else:
    print(-1)

n, m = list(map(int, input().split()))
res, d = -1, 0
if m % n == 0:
    res = 0
    d = m // n
    while d % 2 == 0:
        d, res = d//2, res + 1
    while d % 3 == 0:
        d, res = d//3, res + 1
if d == 1:
    print(res)
else:
    print(-1)


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


import sys
n,m=list(map(int,input().split()))

if m/n!=m//n:
    print(-1)
    return

x=m//n
ANS=0

while x%2==0:
    x=x//2
    ANS+=1

while x%3==0:
    x=x//3
    ANS+=1

if x==1:
    print(ANS)
else:
    print(-1)


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

if b%a == 0:
    c = b//a
    moves = 0
    while c%2 == 0:
        c //= 2
        moves += 1
    while c%3 == 0:
        c //= 3
        moves += 1
    if c == 1:
        print(moves)
    else:
        print(-1)
else:
    print(-1)


n, m = map(int, input().split())

if m % n != 0:
    print(-1)
else:
    x = m // n
    k = 0
    while x % 2 == 0:
        x //= 2
        k += 1
    while x % 3 == 0:
        x //= 3
        k += 1
    if x == 1:
        print(k)
    else:
        print(-1)

n,m = map(int, input().strip().split())
can = True
if m%n != 0:
    can = False
k = m/n
ans = 0
while k%2 == 0:
    k = k/2
    ans += 1
while k%3 == 0:
    k = k/3
    ans += 1
if k != 1:
    can = False
if can:
    print (ans)
else:
    print (-1)

n,m=map(int,input().split())
ans=0
if(m%n==0):
         m//=n
else:
         m=1
         ans=-1
while(m!=1):
         if(m%2==0):
                  m//=2
                  ans+=1
         elif(m%3==0):
                  m//=3
                  ans+=1
         else:
                  ans=-1
                  break
print(ans)

n, m = map(int,input().split())
d = m // n
ans = 0
p = 1
while d % 3 == 0:
    ans += 1
    d //= 3
    p *= 3
while d % 2 == 0:
    ans += 1
    d //= 2
    p *= 2
if d != 1 or p*n != m:
    print(-1)
else:
    print(ans)

n,m=map(int,input().split())
if m%n!=0:
    print(-1)
else:
    m//=n
    ans=0
    while m%2==0:
        m//=2
        ans+=1
    while m%3==0:
        m//=3
        ans+=1
    if m>1:
        print(-1)
    else:
        print(ans)