open System

let n = Console.ReadLine() |> int
let a = Console.ReadLine().Split(' ') |> Array.map int64

let GetXor (xs: int64[]) = Array.fold (fun acc elem -> acc^^^elem) 0L xs

let X = GetXor a.[2..]
let S = a.[0]+a.[1]

if a.[0]^^^a.[1] = X then
    Console.Write(0)
elif S<X then
    Console.Write(-1)
else
    let U = a.[0]
    let D = (S-X)/2L
    let mutable Ans = D
    if D&&&1L = 1L || D&&&X <> 0L then
        Console.Write(-1)
    else
        for i = 40 downto 0 do
            if (X&&&(1L<<<i) <> 0L)&&(Ans|||(1L<<<i) < U) then
                Ans <- Ans|||(1L<<<i)
    if Ans > 0L && Ans < U then
        Console.Write(U-Ans)
    else
        Console.Write(-1)