module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun a -> a in
  Printf.printf "%d\n" @@
    try IntMap.find 0 @@
      Array.fold_left (fun m a ->
        IntMap.fold (fun x n m ->
          IntMap.add (x lxor a lxor (a - 1))
            (min (1 + n) @@
              try IntMap.find (x lxor a lxor (a - 1)) m
              with Not_found -> max_int) m) m m)
      (IntMap.singleton (Array.fold_left ( lxor ) 0 as_) 0) as_
    with Not_found -> -1
