#include #include typedef long long int ln; ln gcd(ln n,ln m){ ln r=n%m; while(r!=0){ n=m; m=r; r=n%m; } return m; } int isFinite(ln m){ while(m%2==0){ m/=2; } while(m%5==0){ m/=5; } return m==1; } void run(void){ ln n,m; scanf("%lld%lld",&n,&m); ln r=gcd(n,m); n/=r; m/=r; if(!isFinite(m)){ printf("-1\n"); return; } while(m%10==0){ m/=10; } if(m%2==0){ printf("5\n"); } else { n=n%10; while(m%5==0){ n=(n*2)%10; m/=5; } printf("%lld\n",n); } return; } int main(void){ run(); return 0; }