#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; ull gcd(ull a, ull b){return (b==0?a:gcd(b,a%b));} ull lcm(ull a, ull b){return a/gcd(a,b)*b;} ull lambda(ull n){ ull ret=1; if(n%8==0) n/=2; for(ull d=2; d<=n; d++){ if(n%d==0){ ull y=d-1; n/=d; while(n%d==0){ n/=d; y*=d; } ret=lcm(ret, y); } } return ret; } int main(){ ull N, M; cin >> N; cin >> M; ll keta = lambda(M) + 1; ll ret = 0; while(N=0){ if(N==0){ cout << ret << endl; return 0; } ret = N/M; N %= M; N *= 10LL; --keta; } cout << -1 << endl; return 0; }