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