#include #include #include int ri() { int n; scanf("%d", &n); return n; } int main() { int a = ri(); int b = ri(); int64_t cur = 0; int cnt = 0; for (; std::abs(cur) <= 4000000000; ) { cur = cur * a + b; cnt++; if (!cur) break; } printf("%d\n", cur ? -1 : cnt); return 0; }