#include using namespace std; int main() { int n = 0, a, b, ans = 0; cin >> a >> b; for (;;) { n = a * n + b; ans++; if (n == 0 || ans >= 1000) break; } if (ans == 1000) { cout << -1 << endl; } else { cout << ans << endl; } }