program cheating_nim
  implicit none
  integer :: n, a, x, m, i, k
  logical :: b(0:31)
  a = 0
  b = .false.
  read(*,*) n
  x = 0
  do i = 1, n
    read(*,*) a
    x = xor(x,a)
    b(trailing_zeros(a)) = .true.
  end do
  m = 0
  do while (x.gt.0)
    k = 31-leading_zeros(x)
    if (b(k)) then
      x = xor(x,2**(k+1)-1)
      m = m+1
    else
      m = -1
      exit
    end if
  end do
  write(*,'(i0)') m
  stop
contains
  real(8) function log2(x)
    implicit none
    real(8), intent(in) :: x
    log2 = log(x)/log(2.d0)
    return
  end function log2
  function leading_zeros(x) result(z)
    implicit none
    integer, intent(in) :: x
    integer :: z
    z = 32
    if (x.eq.0) return
    z = 31-floor(log2(real(x,8)))
    return
  end function leading_zeros
  function trailing_zeros(x) result(z)
    implicit none
    integer, intent(in) :: x
    integer :: z, i
    z = 32
    if (x.eq.0) return
    do i = 0, 31
      if (btest(x,i)) then
        z = i
        exit
      end if
    end do
    return
  end function trailing_zeros
end program cheating_nim