#include "bits/stdc++.h" using namespace std; typedef long long ll; mapprime_factor(ll N){ mapret; for(ll i = 2; i * i <= N; i++){ while(N % i == 0){ ret[i]++; N /= i; } } if(N != 1)ret[N] = 1; return ret; } int main(){ ll N, M; cin >> N >> M; mapmp; for(ll i = 2; i * i <= M; i++){ while(M % i == 0){ mp[i]--; M /= i; } } if(M != 1)mp[M]--; for(ll i = 2; i * i <= N; i++){ while(N % i == 0){ mp[i]++; N /= i; } } if(N != 1)mp[N]++; while(mp[2] < 0 || mp[5] < 0){ mp[2]++; mp[5]++; } ll ans = 1; for(auto it = mp.begin(); it != mp.end(); it++){ if((*it).second < 0){ cout << -1 << endl; return 0; } for(ll i = 0; i < (*it).second; i++){ ans *= (*it).first; while(ans % 10 == 0)ans /= 10; ans %= 10; } } cout << ans << endl; return 0; }