let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  let acc = Array.fold_left ( lxor ) 0 bs in
  Array.init 29 (fun i -> i)
  |> Array.fold_left (fun (ans, bs) i ->
      let bs' =
        List.filter (fun b -> 1 lsl (i - 1) <= b) bs @
        List.filter (fun b -> b < 1 lsl (i - 1)) bs in
      let bs = Array.of_list bs' in
      let mask = (1 lsl i) - 1 in
      (ans lor (Array.fold_left ( lxor ) 0 @@ 
      Array.map (fun a ->
        if
          ((a land (1 lsl i)) <> 0 && n mod 2 <> 0) <>
          (acc land (1 lsl i) <> 0) <>
          match 
            upper_bound 0 n (fun j ->
              (1 lsl i) - (a land mask) <= (bs.(j) land mask))
          with
          | 0 -> (1 lsl i) - (a land mask) <= (bs.(0) land mask)
          | i -> i mod 2 = 0
        then 1 lsl i
        else 0) as_), bs')) (0, Array.to_list bs) 
  |> fst
  |> Printf.printf "%d\n"
