a,b=gets.split(" ").map{|e|e.to_i} n=b ans=1 if a==-1 || b==0 then while n!=0 do n=a*n+b ans+=1 end puts ans else puts -1 end