#include #include #include #include inline int count(long long& n, int x){ int res = 0; while(n % x == 0){res += 1; n /= x;} return res; } long long expr(long long a, int n){ long long res = 1ll; while(n > 0){ if(n & 1){res = res * a % 10ll;} a = a * a % 10ll; n >>= 1; } return res; } int main(){ long long N, M; scanf("%lld %lld", &N, &M); long long g = std::__gcd(N, M); N /= g; M /= g; int n2 = count(M, 2), n5 = count(M, 5); if(M != 1){ puts("-1"); return 0; } while(N % 10 == 0){N /= 10;} N %= 10; int a = std::max(n2, n5) - n2, b = std::max(n2, n5) - n5, c = std::min(a, b); printf("%lld\n", N * expr(2, a-c) * expr(5, b-c) % 10ll); }