import Text.Parsec
import Data.Bits

type Input  = (Int, Int)

input :: Parsec String () Input
input = (,) <$> decimal <* char ' ' <*> decimal <* endOfLine

decimal :: Parsec String () Int
decimal = read <$> many digit

main :: IO ()
main = getContents >>= print . either (error . show) solve . parse input ""

solve :: Input -> Int
solve (_A, _B) = f _A _B
  where
    f 0 b = g b
    f a b = g b `xor` g (a - 1)

    g x = case x `mod` 4 of
      0 -> x
      1 -> 1
      2 -> x `xor` 1
      3 -> 0