module Main
where

import           Data.Array.IArray
import           Data.Bits
import           Data.List

main :: IO ()
main = do
    n <- (read :: String -> Int) <$> getLine
    as <- map (read :: String -> Word) . words <$> getLine
    bs <- map (read :: String -> Word) . words <$> getLine
    print (-1)
    -- print $ foldr1 xor $ map (\k -> eachFigure k as bs) [0..28]

-- keyより大きいところのインデックス
-- 広義単調増加関数であること
upperBoundImpl :: Word -> (Int, Int) -> (Int -> Word) -> Int
upperBoundImpl key (l, r) f =
    let mid = (l + r) `div` 2
    in  if r - l <= 1 then r else
        if f mid <= key
            then upperBoundImpl key (mid, r) f
            else upperBoundImpl key (l, mid) f

upperBound :: Word -> (Int, Int) -> (Int -> Word) -> Int
upperBound key (l, r) f = upperBoundImpl key (l - 1, r) f'
    where f' i = if i < l then minBound :: Word else f i

test :: IO()
test = print $ upperBound 1 (0, 5) $ ((listArray (0, 4) [1, 1, 1, 1, 1] :: Array Int Word) !)

xorOnFigure :: Int -> Int -> (Int -> Word) -> Word
xorOnFigure n k sorted =
    let notCarriers = upperBound (bit (k + 1) - 1) (0, n) sorted
        i = upperBound (bit k - 1) (0, notCarriers) sorted
        j = upperBound (bit (k + 1) + bit k - 1) (notCarriers, n) sorted
        cnt = (notCarriers - i) + (n - j)
    in  if odd cnt then bit k else 0

eachFigure :: Int -> [Word] -> [Word] -> Word
eachFigure k as bs =
    let sorted = listArray (0, length bs - 1)
            $ sort $ map (\x -> x `mod` bit (k + 1)) bs :: Array Int Word
        f a = xorOnFigure (length bs) k $ \i -> (a `mod` bit (k + 1) + (sorted ! i))
    in  sorted `seq` foldr1 xor $ map f as
