#include using namespace std; typedef long long ll; int main() { ll a, b; cin >> a >> b; ll count = 0; ll n = 0; while (1) { n = a * n + b; count++; if (n == 0) { cout << count << endl; return 0; } if (count > 70000000 || (a > 0 && b > 0) || (abs(a) > b)) { cout << -1 << endl; return 0; } } }