{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as B
import Data.Attoparsec.ByteString.Char8
import Data.Bits

type Input  = (Int, Int)
type Output = Int

input :: Parser Input
input = do
  (_A, _B) <- decimalPair
  return (_A, _B)

decimalPair :: Parser (Int, Int)
decimalPair = (,) <$> decimal <* char ' ' <*> decimal <* endOfLine

main :: IO ()
main = B.interact
  $ B.pack . show . either (error "parse err") solve . parseOnly input

solve :: Input -> Output
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