from sys import stdin def main(): input = lambda: stdin.readline()[:-1] A, B = map(int, input().split()) if A > 0 and B > 0: print(-1) return ans, n = 0, 0 while 1: n = A * n + B if not n: break ans += 1 print(ans) main()