#include using ll = long long; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int cnt{ 0 }; ll a, b, n{ 0 }; cin >> a >> b; if (a == 0 && b != 0) { cout << "-1\n"; return 0; } while (1) { if ((a * n > 0 && b > 0) || (a * n < 0 && b < 0)) { cnt = -1; break; } n = a * n + b; ++cnt; if (!n) break; } cout << cnt << "\n"; return 0; }