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
  Array.to_list as_
  |> List.map (fun a -> a lxor (a - 1))
  |> List.sort_uniq compare
  |> List.fold_left (fun m a ->
      IntMap.fold (fun x n m ->
        IntMap.add (x lxor a)
          (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)
  |> fun m ->
      Printf.printf "%d\n" @@
        try IntMap.find 0 m with Not_found -> -1
