https://codeforces.com/problemset/problem/1141/A
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
int main(void)
{
LL a,b; cin>>a>>b;
if(b%a!=0) puts("-1");
else
{
LL n=b/a;
LL ans=0;
while(n%3==0) ans++,n/=3;
while(n%2==0) ans++,n/=2;
if(n!=1) puts("-1");
else cout<<ans;
}
return 0;
}