#include using namespace std; using ll = long long; constexpr long long MOD = 1000000007; int main(){ ll a, b; cin >> a >> b; ll cnt = 0; ll tmp = 0; while (true) { tmp = a * tmp + b; cnt++; if (tmp == 0) break; if (cnt > 2e7) break; } if (cnt >= 2e7) cout << "-1" << endl; else cout << cnt << endl; }