#include long long int gcd( long long int a, long long int b){ if(b == 0){ return a; } if(a > b){ return gcd(b,a%b); }else{ return gcd(a,b%a); } } int main(void){ long long int n,m,g, tmp; scanf("%lld", &n); scanf("%lld", &m); g = gcd(n,m); n /= g; m /= g; tmp = m; while( tmp%2 == 0 ){ tmp/=2;} while( tmp%5 == 0 ){ tmp/=5;} if(tmp == 1){ while( n%m != 0){n*=10;} n /= m; while(n%10==0){n/=10;} n = n%10; printf("%lld\n", n); }else{ printf("-1\n"); } return 0; }