#include #include #include using namespace std; int main() { long long n, m; while (cin>>n>>m) { unordered_set s; auto res=-1LL; while (true) { auto t=n%m; if (!t) { n/=m; while (n%10==0) n/=10; res=n%10; break; } if (s.count(t)) { res=-1; break; } s.insert(t); n%=m; n*=10; } cout<