A,B=map(int, input().split()) N=0 for i in range(1000): d=A*N+B if d==0: print(i+1) exit() N=d print(-1)