A, B = gets.split.map(&:to_i) if A != -1 && B != 0 puts -1 elsif n = B res = 1 while n != 0 n = A * n + B res += 1 end puts res end