intgcd(int a,int b){ return b == 0 ? a : gcd(b,a%b); }
intsolve(){ int a = A , b = B; for(int i = 0; i < 3; i++){ while(a % f[i] == 0) a /= f[i]; } for(int i = 0; i < 3; i++){ while(b % f[i] == 0) b /= f[i]; } if(a != b) return-1; A /= a; B /= b; int g = gcd(A,B); A /= g; B /= g; int ans = 0; a = A; b = B; for(int i = 0; i < 3; i++){ while(a % f[i] == 0){ a /= f[i]; ans++; } } for(int i = 0; i < 3; i++){ while(b % f[i] == 0){ b /= f[i]; ans++; } } return ans; }
intmain(){ while(cin >> A >> B){ if(A == B) puts("0"); elseprintf("%d\n",solve()); } return0; }