program unfair_nim
  implicit none
  integer :: n, i
  integer(8) :: a(300) = 0, s, x = 0, d, y = 0
  read(*,*) n
  read(*,*) a(1:n)
  s = a(1) + a(2)
  do i = 3, n
    x = xor(x, a(i))
  end do
  if (s - x < 0 .or. mod(s - x, 2) /= 0) then
    write(*,'(i0)') -1
    stop
  end if
  d = (s - x) / 2
  if (and(d, x) /= 0 .or. d > a(1)) then
    write(*,'(i0)') -1
    stop
  end if
  do i = 62, 0, -1
    if (.not.btest(x, i)) cycle
    y = ibset(y, i)
    if (xor(d, y) > a(1)) y = ibclr(y, i)
  end do
  write(*,'(i0)') a(1) - xor(d, y)
end program unfair_nim