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