A,B = map(int,input().split()) if A > 0 and B > 0: print(-1) N = 0 for i in range(10): N = A * N + B if N == 0: print(i+1) exit() else: print(-1)