object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a1, a2 = sc.nextLong()
  val s = a1 + a2
  var x = List.fill(n-2)(sc.nextLong()).foldLeft(0L)(_ ^ _)

  if (x > s || ((s - x) & 1) == 1) {
    println(-1)
  } else {
    var d = (s - x) >> 1
    if (d > a1 || (0 to 40).indexWhere(i => ((d >> i) & 1) == 1 && ((x >> i) & 1) == 1) != -1) {
      println(-1)
    } else {
      for (i <- 40 to 0 by -1 if ((x >> i) & 1) == 1 && d + (1L << i) <= a1) {
        d += 1L << i
      }
      if (d == 0) println(-1) else println(a1 - d)
    }
  }
}
