long a,b,p,q,t;main(){scanf("%ld%ld",&a,&b);for(p=a,t=b;q=t;p=q)t=p%q;for(a/=p;a%(q=10)<1;a/=q);for(b/=p;b%q<1;b/=q);for(t=b%2*3+2;b%t<1;a=a*2%q)b/=t;a=!printf("%d",b-1?-1:t-2?a:5);}