import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V

main=do
  n<-readLn::IO Int
  as<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  bs<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  --
  print.sum.map (st n as bs) $ ts (2^27)
--
ts::Int->[Int]
ts t
  | t==1 = [1]
  | True = t:(ts $ t`div`2)

st::Int->[Int]->[Int]->Int->Int
st n as bs t = if even$ sum $ map (f n bs t) as then 0 else t

f::Int->[Int]->Int->Int->Int
f n bs' t a' = b2 - b1 + b4 - b3
  where
    a = a' `mod` (t*2)
    bs = V.fromList.sort.map (flip mod (t*2)) $ bs'
    b1 = bsearch (\i-> (bs V.! i) < (t-a)) (-1,n)
    b2 = bsearch (\i-> (bs V.! i) < (2*t-a)) (-1,n)
    b3 = bsearch (\i-> (bs V.! i) < (3*t-a)) (-1,n)
    b4 = bsearch (\i-> (bs V.! i) < (4*t-a)) (-1,n)

bsearch f (a,b)
    | a+1 == b = a
    | f m  = bsearch f (m,b)
    | True = bsearch f (a,m)
    where m = (a + (b-a)`div`2)