int main(){ long a,b,p,q,t; scanf("%ld%ld",&a,&b); if(a%b<1){for(a/=b;a%10;a/=10);printf("%d",a%10);return 0;} for(p=a,q=b;q;q=t)t=p%q,p=q; a/=p;b/=p; if(b%2<1)puts("5");else{for(a%=10;b&b-1;a*=2)b/=5;printf("%d",b?a%10:-1);} return 0; }