#include using namespace std; using ll = long long; int main() { ll a, b; cin >> a >> b; ll n = 0; for(int i = 0; i <= 1e6; i++) { n = a * n + b; if(abs(n) >= 1e9+10) { cout << -1 << endl; return 0; } if(!n) { cout << i + 1 << endl; return 0; } } cout << -1 << endl; }