#include #include using namespace std; long long a, b; int main() { scanf ("%d %d", &a, &b); long long n = b; int c = 1; while (n || c <= 2){ n = a * n + b; c++; } if (n) c = -1; printf ("%d\n", c); return 0; }