#include using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b, n = 0; cin >> a >> b; ll ans = 0; for (int i = 1; i <= 10000000; i++) { n = a * n + b; if (n == 0) { cout << i << '\n';; return 0; } } cout << "-1\n"; return 0; }