import java.io.BufferedReader

fun main() {
    val br = System.`in`.bufferedReader()
    val n = br.readInt()
    val a1 = br.readLong()
    val a2 = br.readLong()
    var x = 0L
    repeat(n - 2) {
        x = x xor br.readLong()
    }

    val b = a1 + a2 - x
    if (b and 1 != 0L) {
        print(-1)
    } else {
        var a1After = b shr 1
        if (a1After > a1) {
            print(-1)
        } else {
            var good = true
            for (bit in 39 downTo 0) {
                val num = 1L shl bit
                if (num and x != 0L) {
                    if(num and a1After != 0L){
                        good = false
                    }
                    if (num + a1After <= a1) {
                        a1After += num
                    }
                }
            }
            if (!good || a1After == 0L) {
                print(-1)
            } else {
                print(a1 - a1After)
            }
        }
    }
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}

private fun BufferedReader.readLong(): Long {
    var ret = read().toLong()
    while (ret <= SPACE_INT) {
        ret = read().toLong()
    }
    val neg = ret == '-'.toLong()
    if (neg) {
        ret = read().toLong()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }
    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}