#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; map factorize(ull x){ map ret; ull d, q; while(x>=4 && x%2==0){ret[2]++; x/=2;} d = 3; q = x/d; while(q>=d){ if(x%d==0){ ret[d]++; x=q; }else{ d+=2; } q=x/d; } ret[x]++; return ret; } int main(){ ull N, M; cin >> N; cin >> M; map res1 = factorize(N); map res2 = factorize(M); if(res2.count(2) == 0 && res2.count(5) == 0){ cout << -1 << endl; return 0; } FOR(it,res2){ while(res1[it->first]>0 && res2[it->first]>0){ N/=it->first; M/=it->first; res1[it->first]--; res2[it->first]--; } } FOR(it,res2){ if(it->second == 0) continue; if(it->first != 2 && it->first != 5){ cout << -1 << endl; return 0; } } int mx = max(res2[2],res2[5]); res1[2]+=mx; res1[5]+=mx; res1[2]-=res2[2]; res1[5]-=res2[5]; while(res1[2]>0 && res1[5]>0){ res1[2]--; res1[5]--; } ull ret = 1; FOR(it,res1){ rep(i,it->second){ ret *= it->first; ret %= 10; } } cout << ret << endl; return 0; }