{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.Attoparsec.ByteString.Lazy as AL
import qualified Data.Attoparsec.ByteString.Char8 as AC
import Data.Bits

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

inputParser :: AC.Parser Input
inputParser = do
  (_A, _B) <- decimalPair
  return (_A, _B)

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

main :: IO ()
main = do
  contents <- B.getContents
  case AL.parse inputParser contents of
    AL.Done _ input -> print $ solve input
    _               -> error "parse failed"

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