import Data.Bits

calc' [] n = return n
calc' (x:xs) n = calc' xs $ if x then 2 * n + 1 else 2 * n

calc n = do
  let bits = reverse $ take 100 $ map f $ map (2 ^) [1..]
  return bits
  where f i = if i == 2 then (n `mod` 4 == 1 || n`mod` 4 == 2) else if n `mod` i*2 < i then False else even (n `mod` i)

main = do
  (a:b:_) <- map read . words <$> getLine :: IO [Integer]
  if a == 0 then print b else do
    b <- calc b
    a <- calc (a - 1)
    print =<< calc' (zipWith xor a b) 0
