A,B = map(int,input().split()) N = 0 flg = False for i in range(100): N = A*N +B if N == 0: print(i+1) flg = True break if flg == False: print(-1)