a,b = list(map(int, input().split())) n = 0 ans = -1 for i in range(10**6): n = a*n+b if(n==0): ans = i+1 break print(ans)