A,B = [int(zz) for zz in input().split()] if (A%2)+(B%2) == 0: print(-1) else: dp = [[0]*(10**5) for i in range(2)] dp[0][A] = 1 dp[0][0] = 1 for i in range(A+1,10**5): if i%A == 0: dp[0][i] = 1 for i in range(10**5): if i < B: dp[1][i] = dp[0][i] else: dp[1][i] = max(dp[1][i-B],dp[0][i]) print(10**5-sum(dp[1]))