http://codeforces.com/contest/371/problem/B
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll int
using namespace std; ll a,b;
int ans=;
int m1,m2;
int check(ll x)
{
while(x)
{
if(x%==)
x/=;
else if(x%==)
x/=;
else if(x%==)
x/=;
else
{
break;
}
ans++;
}
return x;
} ll gcd(ll c,ll d)
{
return d==?c:gcd(d,c%d);
} int main()
{
cin>>a>>b;
if(a==b)
{
printf("0\n");
return ;
}
int s=gcd(a,b);
a/=s;
b/=s;
if(check(a)==check(b))
{
printf("%d\n",ans);
}
else printf("-1\n");
return ;
}