#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll N, M; cin >> N >> M; ll g = gcd(N, M); N /= g, M /= g; ll X = M; while(X % 2 == 0) X /= 2; while(X % 5 == 0) X /= 5; if(X != 1){ cout << -1 << endl; return 0; } ll ans = 0; while(N > 0){ ll q = N / M; while(q > 0 && q % 10 == 0) q /= 10; if(q % 10 > 0) ans = q % 10; (N %= M) *= 10; } cout << ans << endl; return 0; }