N, M = map(int, input().split()) res = 0 for i in range(30): if M & (1 << i): if N & (1 << i): if not i & 1: res |= 1 << i else: res |= 1 << i elif (not i & 1) and (N & (1 << i)) and not (M & (1 << i)): print(-1) exit() print(res)