#include using namespace std; using ll = long long int; using lc = complex; int main(void) { constexpr ll MOD = 1e9 + 7; constexpr double PI = acos(-1); cout << fixed << setprecision(32); cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; ll n = 0, i = 0; do { n = a*n + b; i++; } while(-1e10 < n && n < 1e10 && n != 0 && i < 1e6); cout << (n == 0 ? i : -1) << endl; }