A, B = map(int, input().split()) n = 0 i = 1 n = A*n+B while n!=0: n = A*n+B i+=1 if i>10: print(-1) exit() print(i)