#include using namespace std; typedef long long ll; #define int ll #define REP(i,n) for(int i=0;i::infinity(); const int MOD = 1000000007; #define MAX_N 100010 signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int A, B; cin >> A >> B; int n = 0; REP(i, 100000) { n = A * n + B; if(n == 0) { printf("%lld\n", i + 1); return 0; } } printf("-1\n"); return 0; }