// yukicoder 25 (http://yukicoder.me/problems/70) #include typedef long long ll; ll N, M; ll gcd( ll a, ll b ) { return b?gcd(b,a%b):a; } int main() { scanf( "%lld%lld", &N, &M ); ll g = gcd( N, M ); N /= g; M /= g; ll p2 = 0, p5 = 0; while( M % 2 == 0 ) ++p2, M>>=1; while( M % 5 == 0 ) ++p5, M/=5; if( M != 1 ) { puts("-1"); return 0; } while( N % 10 == 0 ) N /= 10; while( p2 < p5 ) ++p2, N=(N<<1)%10; while( p2 > p5 ) ++p5, N=(N*5)%10; printf( "%lld\n", N%10 ); return 0; }