a,b=map(int,input().split()) cur=0 for i in range(10**4): cur=a*cur+b if cur==0: print(i+1) exit() print(-1)