#include using namespace std; typedef long long ll; int main(void){ ll a,b; cin >> a >> b; ll res = b; ll cnt = 1; ll ma = res; while(1){ if(res == 0){ cout << cnt << endl; return 0; } //おーばふろーしたか if(res < ma){ cout << -1 << endl; return 0; } res = a*res + b; ma = max(res,ma); cnt++; if(cnt >= 1e5){ cout << -1 << endl; return 0; } } }