#include #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int INF = (1LL << 30) - 1; int MOD = 1e9+7; ll gcd (ll a,ll b){ return b ? gcd(b,a%b) : a; } void divgcd(ll &N,ll &M){ ll g = gcd(N,M); N /= g,M /= g; } main(){ ll N,M; cin >> N >> M; divgcd(N,M); ll k = M; int p[] = {2,5},cnt[2] = {}; rep(i,2){ while(k % p[i] == 0){ k /= p[i]; cnt[i]++; } } if(k != 1){ cout << -1 << endl; return 0; } while(N % 10 == 0)N /= 10; N %= 10; bool flag = cnt[0] > cnt[1]; //|2 - 5| 大きい方をかける回数 while(cnt[0] != cnt[1]){ N = (N * p[flag]) % 10; cnt[flag]++; } cout << N << endl; }