//Normal #define _GLIBCXX_DEBUG #define ll long long #include using namespace std; using Graph = vector>; void print(auto a){ cout << a; } void prints(auto a){ cout << a << " "; } void prints(){ cout << " "; } void printl(auto a){ cout << a << endl; } void printl(){ cout << endl; } void fix(int n){ cout << fixed << setprecision(n); } int siz(string s){ return (int)s.size(); } int main(){ ll A, B; cin >> A >> B; if(B == 0){ printl(1); return 0; } ll X1 = B; ll X2 = A*X1 + B; if(X2 == 0){ printl(2); return 0; } if(X2 > X1){ if(X2 < 0){ for(int i = 3; ; i++){ ll X = A*X2 + B; if(X == 0){ printl(i); return 0; }else if(X > 0){ printl(-1); return 0; } X2 = X; } } }else if(X2 < X1){ if(X2 > 0){ for(int i = 3; ; i++){ int X = A*X2 + B; if(X == 0){ printl(i); return 0; }else if(X < 0){ printl(-1); return 0; } X2 = X; } } } printl(-1); return 0; }