#include #define rep(i,n) for (int (i) = 0; (i) < (n); i++) #define ll long long using namespace std; int main() { ll A = 0,B = 0,N = 0,ans = 0; cin >> A >> B; if(A > 0 && B > 0){ cout << "-1" << endl; return 0; } if(B == 0){ cout << "1" << endl; return 0; } rep(i,10000){ N = A * N + B; ans++; if(N == 0){ cout << ans << endl; return 0; } } cout << "-1" << endl; return 0; }