N, M = [int(s) for s in input().split()] ans = 0 for i in range(31): match (i % 2, (N >> i) & 1, (M >> i) & 1): case (0, 0, 0): ans |= 0 << i case (0, 0, 1): print(-1) exit() case (0, 1, 0): ans |= 0 << i case (0, 1, 1): ans |= 1 << i case (1, 0, 0): ans |= 0 << i case (1, 0, 1): ans |= 1 << i case (1, 1, 0): print(-1) exit() case (1, 1, 1): ans |= 0 << i print(ans)