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