A, B = map(int, input().split()) count = 0 N = 0 if ((A == -1 or A == 1) and A * B < 0) or B == 0: while 1: count += 1 N = A * N + B if N == 0: break print(count) else: print(-1)