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 30 (fun i ->
    let mask = (1 lsl i) - 1 in
    Array.sort (fun x y -> compare (y land mask) (x land mask)) bs;
    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_)
  |> Array.fold_left ( lor ) 0
  |> Printf.printf "%d\n"