A, B = gets.split.map(&:to_i)

a = A%4
b = B%4

# p [a, b]

# p xor(3, 2)

if a  == 0
  if b == 0
    p B
  elsif b == 1
    p 1
  elsif b == 2
    p B+1
  else
    p 0
  end
elsif a == 1
  if b == 0
    p (A-1)^B
  elsif b == 1
    p A
  elsif b == 2
    p A^B
  else
    p A-1
  end
elsif a == 2
  if b == 0
    p B + 1
  elsif b == 1
    p 0
  elsif b == 2
    p B
  else
    p 1
  end
else
  if b == 0
    p A^B
  elsif b == 1
    p A-1
  elsif b == 2
    p (A-1)^B
  else
    p A
  end
end

