a, b = map(int, input().split()) s = [0] for i in range(1, 100): s.append(s[-1] * a + b) if s[-1] == 0: print(i) break else: print(-1)