a,b=map(int,input().split()) x=-b/a if x < 0 or -b%a != 0: print(-1) exit() else: cnt = 0 while True: prev = (x - b)/a cnt += 1 if prev == 0: break x = prev print(cnt)