#include #define all(x) begin(x),end(x) #define rall(x) (x).rbegin(),(x).rend() #define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i) #define rep(i,n) REP(i,0,n) #define repsz(i,v) rep(i,(v).size()) #define aur auto& #define bit(n) (1LL<<(n)) #define eb emplace_back #define mt make_tuple #define fst first #define snd second using namespace std; typedef long long ll; //#define int long long templateint size(const C &c){ return c.size(); } templatebool chmin(T&a,const T&b){if(a<=b)return false;a=b;return true;} templatebool chmax(T&a,const T&b){if(a>=b)return false;a=b;return true;} bool solve(){ ll n, m; cin >> n >> m; ll g = __gcd(n, m); n /= g; m /= g; while(m % 10 == 0) m /= 10; while(n % 10 == 0) n /= 10; n %= 10; for(; m % 2 == 0; m /= 2) (n *= 5) %= 10; for(; m % 5 == 0; m /= 5) (n *= 2) %= 10; if(m != 1) n = -1; cout << n << endl; return true; } signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << std::fixed << std::setprecision(10); solve(); return 0; } // vim:set foldmethod=marker commentstring=//%s: