program unfair_nim
  implicit none
  integer :: n, i
  integer(8) :: a(300) = 0, x = 0, k
  read(*,*) n
  read(*,*) a(1:n)
  do i = 3, n
    x = xor(x, a(i))
  end do
  do k = 0, a(1) - 1
    if (xor(a(1) - k, a(2) + k) == x) then
      write(*,'(i0)') k
      stop
    end if
  end do
  write(*,'(i0)') -1
end program unfair_nim