#include using namespace std; int main() { long long int a, b, n = 0, ans = 0; cin >> a >> b; if (a > 0 && b > 0) { cout << "-1" << "\n"; return 0; } do { int x = n; n = a * n + b; ans++; } while (n != 0); cout << ans << "\n"; }