Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.

Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).

Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?


-----Input-----

The first line of the input contains an integer n (1 ≤ n ≤ 2·10^9) — the number of movements made by the operator.

The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.


-----Output-----

Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.


-----Examples-----
Input
4
2

Output
1

Input
1
1

Output
0



-----Note-----

In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.  During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.  During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.  During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.  Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.

Difficulty: EASY
Tags: Mathematics

Implementation

Constructive algorithms

Starter code:

Solutions:
x = int(input())
y = int(input())
t1 = x % 6
t2 = x % 6
t3 = x % 6
if (t1 == 3 and y == 0 or (t1 == 4 and y == 0)) or (t1 == 2 and y == 1 or (t1 == 5 and y == 1)) or (t1 == 1 and y == 2 or (t1 == 0 and y == 2)):
	print('2')
elif (t2 == 1 and y == 1 or (t2 == 4 and y == 1)) or (t2 == 2 and y == 2 or (t2 == 3 and y == 2)) or (t2 == 0 and y == 0 or (t2 == 5 and y == 0)):
	print('0')
elif (t3 == 1 and y == 0 or (t3 == 2 and y == 0)) or (t3 == 3 and y == 1 or (t3 == 0 and y == 1)) or (t3 == 4 and y == 2 or (t3 == 5 and y == 2)):
	print('1')


n = int(input())
x = int(input())
n %= 6
arr = ['012', '102', '120', '210', '201', '021']
print(arr[n][x])


mov_num = int(input())
nap_num = int(input())
mov_num %= 6
a0 = [0, 1, 2, 2, 1, 0, 0, 1]
a1 = [1, 0, 0, 1, 2, 2, 1, 0]
a2 = [2, 2, 1, 0, 0, 1, 2, 2]
b1 = [1, 0, 2]
b2 = [2, 0, 1]
b3 = [2, 1, 0]
b4 = [1, 2, 0]
b5 = [0, 2, 1]
b6 = [0, 1, 2]
if mov_num == 0:
	print(b6[b6.index(nap_num)])
elif mov_num == 1:
	print(b6[b1.index(nap_num)])
elif mov_num == 2:
	print(b6[b2.index(nap_num)])
elif mov_num == 3:
	print(b6[b3.index(nap_num)])
elif mov_num == 4:
	print(b6[b4.index(nap_num)])
elif mov_num == 5:
	print(b6[b5.index(nap_num)])


def get_pos(x, y):
	if x >= y:
		return y - 1
	return y % x - 1

def solve(n, x):
	a1 = [1, 2, 2, 1, 0, 0]
	a2 = [0, 0, 1, 2, 2, 1]
	pos1 = get_pos(len(a1), n)
	if a1[pos1] == x:
		return 0
	pos2 = get_pos(len(a2), n)
	if a2[pos2] == x:
		return 1
	return 2

def main():
	n = int(input())
	x = int(input())
	print(solve(n, x))
main()


num_moves = int(input()) % 6
found_position = int(input())
while num_moves > 0:
	if num_moves % 2 == 0:
		if found_position == 2:
			found_position = 1
		elif found_position == 1:
			found_position = 2
	elif found_position == 1:
		found_position = 0
	elif found_position == 0:
		found_position = 1
	num_moves -= 1
print(found_position)


a = ['012', '102', '120', '210', '201', '021']
print(a[int(input()) % 6][int(input())])


def simulate(init, n):
	a = [0, 0, 0]
	a[init] = 1
	n %= 6
	for i in range(1, n + 1):
		if i % 2 == 1:
			(a[0], a[1]) = (a[1], a[0])
		else:
			(a[1], a[2]) = (a[2], a[1])
	for i in range(3):
		if a[i] == 1:
			return i
n = int(input())
x = int(input())
for i in range(3):
	if simulate(i, n) == x:
		print(i)
		break


n = int(input(''))
x = int(input(''))
v = [1, 2, 3]
a1 = [2, 1, 3, 2, 3, 1, 3, 2, 1, 3, 1, 2, 1, 3, 2, 1, 2, 3]
n1 = n % 6
b = a1[(n1 - 1) * 3 + x]
print(v.index(b))


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
from array import *

def main():
	n = inin()
	n = n % 6
	x = inin()
	T = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
	if T[n][x] == 0:
		print('0')
	elif T[n][x] == 1:
		print('1')
	elif T[n][x] == 2:
		print('2')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


n = int(input())
m = int(input())
n = n % 6
arr = [0, 0, 0]
arr[m] = 1
for i in range(6 - n):
	j = 6 - n + i
	if j % 2 == 0:
		(arr[0], arr[1]) = (arr[1], arr[0])
	else:
		(arr[1], arr[2]) = (arr[2], arr[1])
print(arr.index(1))


n = int(input())
ball = int(input())
n = n % 6
while n > 0:
	if n % 2 == 1:
		if ball == 0:
			ball = 1
		elif ball == 1:
			ball = 0
	elif n % 2 == 0:
		if ball == 1:
			ball = 2
		elif ball == 2:
			ball = 1
	n -= 1
print(ball)


n = int(input())
x = int(input())
i = n
while i > 0:
	if i % 2 == 0:
		if x == 1:
			x = 2
		elif x == 2:
			x = 1
		if x == 0:
			i %= 6
	elif x == 1:
		x = 0
	elif x == 0:
		x = 1
	i -= 1
print(x)


from sys import stdin
(n, el) = stdin.read().split()
start = [0, 0, 0]
start[int(el)] = 1
n = int(n)
num_op = int(n / 6)
num_r = n - num_op * 6
op = 6 if not num_r else num_r
while op:
	if not op % 2:
		(start[1], start[2]) = (start[2], start[1])
	else:
		(start[0], start[1]) = (start[1], start[0])
	op -= 1
for (i, el) in enumerate(start):
	if el == 1:
		print(i)
		break


n = int(input())
x = int(input())
if x == 2:
	n = n % 6
	if n == 0:
		print(2)
	elif n == 1:
		print(2)
	elif n == 2:
		print(0)
	elif n == 3:
		print(0)
	elif n == 4:
		print(1)
	else:
		print(1)
elif x == 1:
	n = n % 3
	if n == 0:
		print(1)
	elif n == 1:
		print(0)
	else:
		print(2)
else:
	n = n % 6
	if n == 0:
		print(0)
	elif n == 1:
		print(1)
	elif n == 2:
		print(1)
	elif n == 3:
		print(2)
	elif n == 4:
		print(2)
	else:
		print(0)


a = [0, 1, 2]
b = []
b.append(a.copy())
for x in range(1, 6):
	if x % 2 == 1:
		(a[0], a[1]) = (a[1], a[0])
	else:
		(a[1], a[2]) = (a[2], a[1])
		pass
	b.append(a.copy())
n = int(input())
xx = int(input())
n %= 6
print(b[n][xx])


n = int(input())
x = int(input())
n = n % 6
for i in range(n - 1, -1, -1):
	if (i + 1) % 2 == 0:
		if x == 1:
			x = 2
		elif x == 2:
			x = 1
	if (i + 1) % 2 == 1:
		if x == 1:
			x = 0
		elif x == 0:
			x = 1
print(x)


n = int(input())
n %= 6
x = int(input())
m = [(0, 1, 2), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1), (0, 1, 2)]
print(m[n][x])


n = int(input().strip())
x = int(input().strip())
n %= 6

def f(position, times):
	for i in range(times):
		if i % 2 == 0:
			if position == 1:
				position = 0
			elif position == 0:
				position = 1
		elif position == 2:
			position = 1
		elif position == 1:
			position = 2
	return position
for i in range(3):
	if f(i, n) == x:
		print(i)


n = int(input())
x = int(input())
res = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
pos = n % 6
print(res[pos][x])


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = iinp()
x = iinp()
n %= 6
ml = ['012', '102', '201', '210', '120', '021']
print(ml[n].index(str(x)))


def main():
	n = int(input()) % 6
	x = int(input())
	data = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
	print(data[n][x])
main()


n = int(input())
x = int(input())
r = n % 6
if x == 0:
	if r == 5 or r == 0:
		print(0)
	elif r == 1 or r == 2:
		print(1)
	else:
		print(2)
elif x == 1:
	if r == 1 or r == 4:
		print(0)
	elif r == 3 or r == 0:
		print(1)
	else:
		print(2)
elif x == 2:
	if r == 2 or r == 3:
		print(0)
	elif r == 4 or r == 5:
		print(1)
	else:
		print(2)


l = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = int(input())
x = int(input())
a = n % 6
print(l[a][x])


n = int(input())
x = int(input())
a = [0, 1, 2]
for i in range(1, int(n % 6) + 1):
	if i % 2 == 0:
		(a[1], a[2]) = (a[2], a[1])
	else:
		(a[0], a[1]) = (a[1], a[0])
print(a[x])


n = int(input())
x = int(input())
state = [(0, 1, 2), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1)]
s2 = state[n % 6]
print(state[n % 6][x])


l = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1], [0, 1, 2]]
n = int(input()) % 6
m = int(input())
print(l[n][m])


nb_moves = int(input())
ball_at = int(input())
ball = [0, 0, 0]
nb_moves %= 6
ball[ball_at] = 1
for i in range(nb_moves, 0, -1):
	if i % 2 == 0:
		(ball[2], ball[1]) = (ball[1], ball[2])
	else:
		(ball[1], ball[0]) = (ball[0], ball[1])
print(ball.index(1))


(n, l) = (int(input()), int(input()))
a = ['012', '102', '120', '210', '201', '021']
print(a[n % 6][l])


import sys
n = int(input())
m = int(input())
z = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(z[n % 6][m])


import sys
read = lambda : sys.stdin.readline().strip()
write = lambda x: sys.stdout.write(str(x) + '\n')
(n, x) = (int(read()), int(read()))
k = n % 6
table = {0: [(0, 5), (1, 2), (3, 4)], 1: [(1, 4), (0, 3), (2, 5)], 2: [(2, 3), (4, 5), (0, 1)]}
for (idx, alt) in enumerate(table[x]):
	if k in alt:
		write(idx)


a = int(input())
b = int(input())
c = [1, 0, 2]
if b == 1:
	print(c[a % 3])
elif b == 2:
	if a % 3 != 0 and (a % 6 != 1 and a % 6 != 2):
		print(1)
	elif a % 3 != 1 and (a % 6 == 2 or a % 6 == 3):
		print(0)
	else:
		print(2)
elif a % 3 != 0 and (a % 6 == 1 or a % 6 == 2):
	print(1)
elif a % 3 != 2 and (a % 6 != 0 and a % 6 != 1):
	print(2)
else:
	print(0)


a = int(input())
b = int(input())
a %= 6
if a is 0:
	print(b)
else:
	if a is 1:
		result = {0: 1, 1: 0, 2: 2}
	if a is 2:
		result = {0: 1, 1: 2, 2: 0}
	if a is 3:
		result = {0: 2, 1: 1, 2: 0}
	if a is 4:
		result = {0: 2, 1: 0, 2: 1}
	if a is 5:
		result = {0: 0, 1: 2, 2: 1}
	print(result[b])


a = [0, 1, 2]
b = [1, 0, 2]
c = [1, 2, 0]
d = [2, 1, 0]
e = [2, 0, 1]
f = [0, 2, 1]
g = [0, 1, 2]
z = [a, b, c, d, e, f, g]
n = int(input())
x = int(input())
print(z[n % 6][x])


n = int(input())
x = int(input())

def csns(n, x):
	if n % 2 == 0:
		if x == 0:
			return 0
		elif x == 1:
			return 2
		else:
			return 1
	elif x == 0:
		return 1
	elif x == 1:
		return 0
	else:
		return 2
z = n % 6
for i in range(z, 0, -1):
	x = csns(i, x)
print(x)


n = int(input())
x = int(input())
boards = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(boards[n % 6][x])


n = int(input())
t = int(input())
n %= 6
e = [0, 1, 2]
for i in range(n):
	if i % 2 == 0:
		(e[0], e[1]) = (e[1], e[0])
	else:
		(e[1], e[2]) = (e[2], e[1])
print(e[t])


p = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(p[int(input()) % 6][int(input())])


n = int(input())
pos = int(input())
n %= 6
if pos == 0:
	if n == 1 or n == 2:
		print('1')
	elif n == 3 or n == 4:
		print('2')
	else:
		print('0')
elif pos == 1:
	if n == 3 or n == 0:
		print('1')
	elif n == 2 or n == 5:
		print('2')
	else:
		print('0')
elif n == 4 or n == 5:
	print('1')
elif n == 1 or n == 0:
	print('2')
else:
	print('0')


def main():
	n = int(input())
	outpos = int(input())
	even = {'ini1': [1, 2, 0], 'ini2': [2, 0, 1], 'ini3': [0, 1, 2]}
	odd = {'ini1': [1, 0, 2], 'ini2': [2, 1, 0], 'ini3': [0, 2, 1]}
	if n % 2 == 0:
		if n % 6 == 2:
			print(even['ini1'][outpos])
		elif n % 6 == 4:
			print(even['ini2'][outpos])
		elif n % 6 == 0:
			print(even['ini3'][outpos])
	elif n % 6 == 5:
		print(odd['ini3'][outpos])
	elif n % 6 == 3:
		print(odd['ini2'][outpos])
	elif n % 6 == 7:
		print(odd['ini1'][outpos])
	else:
		print(odd['ini1'][outpos])
main()


m = int(input())
p = int(input())
if p == 0:
	print((m + 1) // 2 % 3)
elif p == 1:
	print((0, 2, 1)[(m - 1) % 3])
else:
	print((2, 0, 1)[m % 6 // 2])


n = int(input()) % 6
a = int(input())
B = [0, 0, 0]
B[a] = 1
for i in range(n, 0, -1):
	if i % 2 == 0:
		(B[1], B[2]) = (B[2], B[1])
	else:
		(B[0], B[1]) = (B[1], B[0])
print(B.index(1))


a = [0, 1, 2]
n = int(input())
x = int(input())
while n >= 7:
	n %= 6
if n == 0:
	n = 6
if n == 1:
	a = [1, 0, 2]
if n == 2:
	a = [1, 2, 0]
if n == 3:
	a = [2, 1, 0]
if n == 4:
	a = [2, 0, 1]
if n == 5:
	a = [0, 2, 1]
if n == 6:
	a = [0, 1, 2]
if x == 0:
	print(a[0])
if x == 1:
	print(a[1])
if x == 2:
	print(a[2])


n = int(input())
x = int(input())
board = [0, 0, 0]
board[x] = 1
n = n % 6
for i in range(n - 1, -1, -1):
	if i % 2 != 0:
		(board[1], board[2]) = (board[2], board[1])
	else:
		(board[0], board[1]) = (board[1], board[0])
print(board.index(1))


n = int(input())
i = int(input())
l = [0] * 3
l[i] = 1
n %= 6
while n:
	n -= 1
	if n % 2 == 0:
		(l[0], l[1]) = (l[1], l[0])
	else:
		(l[1], l[2]) = (l[2], l[1])
print(l.index(1))


t = int(input())
pos = int(input())
s = [False, False, False]
s[pos] = True
for i in range(3):
	p = t - i
	rem = p % 3
	if rem == 1 and pos == 1:
		ans = 0
		break
	if rem == 0 and pos == 1:
		ans = 1
		break
	if rem == 2 and pos == 1:
		ans = 2
		break
	if p % 2 == 0:
		if s[1] == 1 or s[2] == 1:
			s[1] = not s[1]
			s[2] = not s[2]
			if s[1] == True:
				pos = 1
			else:
				pos = 2
	elif s[0] == 1 or s[1] == 1:
		s[0] = not s[0]
		s[1] = not s[1]
		if s[0] == True:
			pos = 0
		else:
			pos = 1
print(ans)


(N, Pos) = (int(input()), int(input()))
if N % 3 == 0:
	Line = [0, 1, 2]
elif N % 3 == 1:
	Line = [1, 0, 2]
elif N % 3 == 2:
	Line = [1, 2, 0]
if N // 3 % 2 == 0:
	pass
else:
	Line.reverse()
print(Line[Pos])


def solve():
	n = int(input())
	num = n % 6
	k = int(input())
	arr = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
	print(arr[num][k])
solve()


n = int(input())
x = int(input())
t = [False, False, False]
t[x] = True
for i in range(n % 6, 0, -1):
	if i % 2 == 0:
		(t[1], t[2]) = (t[2], t[1])
	else:
		(t[0], t[1]) = (t[1], t[0])
print(t.index(True))


(n, x) = (int(input()) % 6, int(input()))
data = [0, 0, 0]
data[x] = 1
while n > 0:
	step = n % 2
	(data[2 - step], data[1 - step]) = (data[1 - step], data[2 - step])
	n -= 1
print(data.index(1))


import sys

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def solve():
	shells = [False] * 3
	n = int(input())
	x = int(input())
	shells[x] = True
	n %= 6
	for i in range(n, 0, -1):
		if i % 2:
			(shells[0], shells[1]) = (shells[1], shells[0])
		else:
			(shells[1], shells[2]) = (shells[2], shells[1])
	for i in range(3):
		if shells[i]:
			print(i)
			return None
solve()


from sys import stdin
N = int(stdin.readline().rstrip())
X = int(stdin.readline().rstrip())
moves = N % 6
shells = [False, False, False]
shells[X] = True
for m in range(moves):
	if moves % 2 == 0 and m % 2 == 0 or (moves % 2 == 1 and m % 2 == 1):
		temp = shells[2]
		shells[2] = shells[1]
		shells[1] = temp
	else:
		temp = shells[0]
		shells[0] = shells[1]
		shells[1] = temp
for s in range(0, 3):
	if shells[s]:
		print(s)


movements = int(input())
position = int(input())
lis = ['012', '102', '120', '210', '201', '021']
print(lis[movements % 6][position])


n = eval(input())
x = eval(input())
n = n % 6
if n == 0:
	n = 6
a = [0] * 3
a[1] = 1
a[2] = 2
for i in range(1, n + 1):
	if i % 2 == 1:
		(a[0], a[1]) = (a[1], a[0])
	else:
		(a[1], a[2]) = (a[2], a[1])
print(a[x])


n = int(input())
x = int(input())
n %= 6
for i in range(n, 0, -1):
	if i % 2 == 0 and x != 0:
		if x == 2:
			x = 3
		else:
			x = 2
	if i % 2 == 1 and x != 2:
		if x == 0:
			x = 1
		else:
			x = 0
print(x)


n = int(input()) % 30
x = int(input())
for i in range(n, 0, -1):
	if i % 2 == 0:
		if x == 1 or x == 2:
			x = 3 - x
	elif x == 0 or x == 1:
		x = 1 - x
print(x)


n = int(input(''))
x = int(input(''))
nums = [0, 1, 2, 2, 1, 0]
if nums[n % 6] == x:
	print(0)
elif nums[(n - 2) % 6] == x:
	print(1)
else:
	print(2)


n = int(input())
x = int(input())
a = [0] * 3
a[x] = 1
n = n % 6
if n == 0:
	print(a.index(1))
elif n == 1:
	(a[0], a[1]) = (a[1], a[0])
	print(a.index(1))
elif n == 2:
	(a[2], a[1]) = (a[1], a[2])
	(a[0], a[1]) = (a[1], a[0])
	print(a.index(1))
elif n == 3:
	(a[0], a[2]) = (a[2], a[0])
	print(a.index(1))
elif n == 4:
	(a[0], a[2]) = (a[2], a[0])
	(a[0], a[1]) = (a[1], a[0])
	print(a.index(1))
elif n == 5:
	(a[2], a[1]) = (a[1], a[2])
	print(a.index(1))


n = int(input())
x = int(input())
d = n % 6
rs = [[1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1], [0, 1, 2]]
print(rs[d - 1][x])


def f(l):
	(n, x) = l
	h0 = [0, 1, 1, 2, 2, 0]
	h1 = [1, 0, 2, 1, 0, 2]
	h2 = [2, 2, 0, 0, 1, 1]
	hs = [h0, h1, h2]
	return hs[x][n % 6]
l = [int(input()) for _ in range(2)]
print(f(l))


moves = int(input()) % 6
position = int(input())
zeros = [0, 1, 2, 2, 1, 0]
ones = [1, 0, 0, 1, 2, 2]
twos = [2, 2, 1, 0, 0, 1]
if zeros[moves] == position:
	print('0')
if ones[moves] == position:
	print('1')
if twos[moves] == position:
	print('2')


n = int(input())
m = int(input())
s = [0, 0, 0]
s[m] = 1
for i in range(n % 6, 0, -1):
	if i % 2 == 0:
		(s[1], s[2]) = (s[2], s[1])
	else:
		(s[0], s[1]) = (s[1], s[0])
for i in range(3):
	if s[i]:
		print(i)


n = int(input())
x = int(input())
for i in range(3):
	arr = [0, 0, 0]
	arr[i] = 1
	for j in range(1, n % 6 + 1):
		if j % 2 == 1:
			tmp = arr[0]
			arr[0] = arr[1]
			arr[1] = tmp
		else:
			tmp = arr[1]
			arr[1] = arr[2]
			arr[2] = tmp
	if arr[x] == 1:
		print(i)
		break


n = int(input())
n = n % 6
x = int(input())
(a, b, c) = (0, 1, 2)
for i in range(1, n + 1):
	if i % 2 == 1:
		(a, b) = (b, a)
	else:
		(b, c) = (c, b)
d = [a, b, c]
print(d[x])


numb = [0, 0, 1, 2, 2, 1]
chart = [1, 0, 5, 2, 3, 4]
add = int(input())
start = int(input())
start = 2 * start
if add % 2 == 0:
	start += 1
add = (add + chart[start]) % 6
print(numb[add])


def main():
	n = int(input()) % 6
	x = int(input())
	for y in range(n):
		if (n - y) % 2 == 0:
			if x == 0:
				x = 0
			elif x == 1:
				x = 2
			elif x == 2:
				x = 1
		elif x == 0:
			x = 1
		elif x == 1:
			x = 0
		elif x == 2:
			x = 2
	print(x)
main()


n = int(input())
x = int(input())
l0 = [1, 2, 2, 1, 0, 0]
l1 = [0, 0, 1, 2, 2, 1]
l2 = [2, 1, 0, 0, 1, 2]
ind = n % 6 - 1
if l0[ind] == x:
	print(0)
elif l1[ind] == x:
	print(1)
else:
	print(2)


n = int(input())
a = int(input())
A = [[0, 1, 2, 2, 1, 0], [1, 0, 0, 1, 2, 2], [2, 2, 1, 0, 0, 1]]
n %= 6
if A[0][n] == a:
	print(0)
elif A[1][n] == a:
	print(1)
else:
	print(2)


from sys import stdin
N = int(stdin.readline())
X = int(stdin.readline())
moves = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(moves[N % len(moves)][X])


from sys import stdin, stdout
n = int(stdin.readline()) % 6
num = int(stdin.readline())
ans = [0, 1, 2]
while n > 1:
	ans = ans[1:] + [ans[0]]
	n -= 2
if n:
	(ans[0], ans[1]) = (ans[1], ans[0])
stdout.write(str(ans[num]))


N = int(input())
X = int(input())
N %= 6
L = [0, 1, 2]
flg = True
for i in range(N):
	if flg:
		(L[0], L[1]) = (L[1], L[0])
	else:
		(L[1], L[2]) = (L[2], L[1])
	flg = not flg
print(L[X])


n = int(input())
x = int(input())
s = [2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1]
pos = s.index(x)
a = n % 6
b = n % 2
st = -1
if (x == 2 or x == 1) and b == 0:
	st = s.index(x, pos + 1)
elif (x == 2 or x == 1) and b == 1:
	st = pos
elif x == 0 and b == 0:
	st = pos
elif x == 0 and b == 1:
	st = s.index(x, pos + 1)
print(s[st + a])


n = int(input())
x = int(input())
k = n % 6
a = [0] * 3
a[x] = 1
for i in range(n, n - k, -1):
	if i % 2 != 0:
		(a[0], a[1]) = (a[1], a[0])
	else:
		(a[1], a[2]) = (a[2], a[1])
for i in range(len(a)):
	if a[i]:
		print(i)


n = int(input())
x = int(input())
n = n % 6
for i in range(3):
	d = [0, 0, 0]
	d[i] = 1
	for j in range(n):
		if j % 2 == 0:
			(d[0], d[1]) = (d[1], d[0])
		else:
			(d[1], d[2]) = (d[2], d[1])
	for j in range(3):
		if d[j] == 1:
			if j == x:
				print(i)
				exit()


k = int(input())
a = [0] * 3
a[int(input())] = 1
for x in range(k % 6, 0, -1):
	if x % 2 == 1:
		(a[0], a[1]) = (a[1], a[0])
	else:
		(a[1], a[2]) = (a[2], a[1])
print(a.index(1))


n = int(input())
k = int(input())
ans = [[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2], [1, 3, 2]]
print(ans[n % 6][k] - 1)


ans = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1], [0, 1, 2]]
print(ans[int(input()) % 6][int(input())])


import math

def solve():
	n = int(input())
	x = int(input())
	ck = [0, 0, 0]
	ck[x] = 1
	n %= 6
	for i in range(n, 0, -1):
		temp = ck[1]
		ck[1] = ck[2] if i % 2 == 0 else ck[0]
		if i % 2 == 0:
			ck[2] = temp
		else:
			ck[0] = temp
	for i in range(0, 3):
		if ck[i] == 1:
			print(i)
			return
t = 1
while True:
	solve()
	t -= 1
	if t <= 0:
		break


A = [0, 1, 2]
B = [0] * 6
for i in range(6):
	B[i] = A[:]
	if i % 2 == 0:
		(A[0], A[1]) = (A[1], A[0])
	else:
		(A[1], A[2]) = (A[2], A[1])
n = int(input())
n %= 6
x = int(input())
print(B[n][x])


n = int(input())
p = int(input())
if n % 2 == 0:
	print(int((n // 2 + p) % 3))
elif p == 0:
	print((n // 2 + 1) % 3)
elif p == 1:
	print((n // 2 + 0) % 3)
else:
	print((n // 2 + 2) % 3)


n = int(input())
a = ['012', '102', '120', '210', '201', '021']
t = int(input())
print(a[n % len(a)][t])


x = int(input())
n = int(input())
st = n
if x % 4 == 1:
	if n == 1:
		st = 0
	if n == 2:
		st = 2
	if n == 0:
		st = 1
if x % 4 == 2:
	if n == 1:
		st = 2
	if n == 2:
		st = 0
	if n == 0:
		st = 1
if x % 4 == 3:
	if n == 1:
		st = 1
	if n == 2:
		st = 0
	if n == 0:
		st = 2
sts = x // 4
if sts % 3 == 0:
	print(st)
if sts % 3 == 1:
	print((st - 1) % 3)
if sts % 3 == 2:
	print((st - 2) % 3)


(n, x) = (int(input()), int(input()))
if (n % 6 == 0 or n % 6 == 5) and x == 0:
	print(0)
elif n == 1 and x == 0:
	print(1)
elif n == 1 and x == 2:
	print(2)
elif n == 2 and x == 1:
	print(2)
elif n == 3 and x == 0:
	print(2)
elif ((n - 2) % 6 == 0 or (n - 2) % 6 == 5) and x == 0:
	print(1)
elif ((n - 4) % 6 == 0 or (n - 4) % 6 == 5) and x == 0:
	print(2)
elif (n % 6 == 1 or n % 6 == 4) and x == 1:
	print(0)
elif ((n - 2) % 6 == 1 or (n - 2) % 6 == 4) and x == 1:
	print(1)
elif ((n - 4) % 6 == 1 or (n - 4) % 6 == 4) and x == 1:
	print(2)
elif (n % 6 == 2 or n % 6 == 3) and x == 2:
	print(0)
elif ((n - 2) % 6 == 2 or (n - 2) % 6 == 3) and x == 2:
	print(1)
elif ((n - 4) % 6 == 2 or (n - 4) % 6 == 3) and x == 2:
	print(2)


(Check, N) = ([False] * 3, int(input()) % 6)
Check[int(input())] = True
while N != 0:
	if N % 2 == 0:
		(Check[2], Check[1]) = (Check[1], Check[2])
	else:
		(Check[0], Check[1]) = (Check[1], Check[0])
	N -= 1
print(Check.index(True))


n = int(input())
fin_pos = int(input())
n = n % 6
a = [0, 1, 2]
changes_made = {}
for i in range(1, 7):
	if i % 2 == 1:
		(a[0], a[1]) = (a[1], a[0])
		b = a.copy()
		changes_made[i] = b
	else:
		(a[1], a[2]) = (a[2], a[1])
		b = a.copy()
		changes_made[i] = b
changes_made[0] = changes_made[6]
start_pos = changes_made[n][fin_pos]
print(start_pos)


A = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = int(input())
x = int(input())
n = n % 6
print(A[0].index(A[n][x]))


n = int(input())
x = int(input())
n -= 1
n %= 6
l = [[1, 2, 2, 1, 0, 0], [0, 0, 1, 2, 2, 1], [2, 1, 0, 0, 1, 2]]
for i in range(3):
	if l[i][n] == x:
		print(i)
		break


def main():
	read = lambda : tuple(map(int, input().split()))
	(n, k) = (read()[0], read()[0])
	n %= 6
	l = [0, 1, 2]

	def swap(a, b):
		tmp = l[a]
		l[a] = l[b]
		l[b] = tmp
	for i in range(1, n + 1):
		if i % 2 == 0:
			swap(1, 2)
		else:
			swap(0, 1)
	print(l[k])
main()


__author__ = 'Ryabchun Vladimir'
naperstki = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = int(input())
x = int(input())
if n < 6:
	ball_index = naperstki[n][x]
	print(naperstki[0].index(ball_index))
else:
	n %= 6
	ball_index = naperstki[n][x]
	print(naperstki[0].index(ball_index))


n = int(input())
x = int(input())
y = n % 6
spis = ['012', '102', '120', '210', '201', '021']
a = spis[y][x]
print(spis[0].index(a))


x = int(input())
y = int(input())
lst = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
x = x % 6
print(lst[x][y])


n = int(input())
x = int(input())
l = ['s', 's']
l.insert(x, x)
if n < 6:
	for i in range(n, 0, -1):
		if i % 2 == 0:
			(l[1], l[2]) = (l[2], l[1])
		if i % 2 != 0:
			(l[0], l[1]) = (l[1], l[0])
else:
	if x == 0:
		n = n % 6
	if x == 1:
		n = n % 3
	if x == 2:
		n = n % 6
	for i in range(n, 0, -1):
		if i % 2 == 0:
			(l[1], l[2]) = (l[2], l[1])
		if i % 2 != 0:
			(l[0], l[1]) = (l[1], l[0])
print(l.index(x))


num_turns = int(input())
end_pos = int(input())
zero_first_pos = [0, 1, 1, 2, 2, 0]
one_first_pos = [1, 0, 2, 1, 0, 2]
two_first_pos = [2, 2, 0, 0, 1, 1]
if end_pos == 0:
	print(zero_first_pos[num_turns % 6])
elif end_pos == 1:
	print(one_first_pos[num_turns % 6])
else:
	print(two_first_pos[num_turns % 6])


n = int(input())
k = int(input())
pos = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(pos[n % 6][k])


print({0: 0, 4: 0, 8: 0, 11: 0, 13: 0, 15: 0, 1: 1, 3: 1, 6: 1, 10: 1, 14: 1, 17: 1, 2: 2, 5: 2, 7: 2, 9: 2, 12: 2, 16: 2}[int(input()) % 6 * 3 + int(input())])


n = int(input())
x = int(input())
seq = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
p = n % 6
print(seq[p][x])


N = int(input()) % 6
X = int(input())
for i in range(N, 0, -1):
	if i & 1 and X < 2:
		X = 1 - X
	elif ~i & 1 and X:
		X = 3 - X
print(X)


n = int(input())
b = int(input())
if n == 0:
	print(b)
	exit()
a0 = [0, 1, 2, 2, 1, 0]
a1 = [1, 0, 0, 1, 2, 2]
a2 = [2, 2, 1, 0, 0, 1]
k = n % 6
if b == a0[k]:
	print(0)
elif b == a1[k]:
	print(1)
else:
	print(2)


Turn = int(input())
m = int(input())
A = {2: ((2, 3), (4, 5), (0, 1)), 0: ((5, 0), (1, 2), (3, 4)), 1: ((1, 4), (3, 0), (5, 2))}
Num = Turn % 6
if Num in A[m][0]:
	print(0)
elif Num in A[m][1]:
	print(1)
elif Num in A[m][2]:
	print(2)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return list(map(int, input().split()))

def II():
	return int(input())

def LS():
	return input().split()

def S():
	return input()

def main():
	n = II()
	x = II()
	a = [0, 1, 2]
	n %= 6
	for i in range(n):
		if i % 2 == 0:
			(a[0], a[1]) = (a[1], a[0])
		else:
			(a[2], a[1]) = (a[1], a[2])
	return a[x]
print(main())


import sys
cups = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = int(input())
x = int(input())
m = n % 6
print(cups[m][x])


n = int(input())
n %= 6
pos = int(input())
(a, b, c) = (0, 0, 0)
if pos == 0:
	a = 1
elif pos == 1:
	b = 1
elif pos == 2:
	c = 1
for i in range(n, 0, -1):
	if i % 2 == 0:
		(b, c) = (c, b)
	else:
		(a, b) = (b, a)
res = -1
if a == 1:
	print(0)
elif b == 1:
	print(1)
elif c == 1:
	print(2)


ret_map = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = int(input())
x = int(input())
print(ret_map[n % 6][x])


n = int(input())
index = int(input())
n = n % 6
boxes = [False] * 3
boxes[index] = True
while n > 0:
	if n % 2 != 0:
		(boxes[0], boxes[1]) = (boxes[1], boxes[0])
	else:
		(boxes[1], boxes[2]) = (boxes[2], boxes[1])
	n -= 1
print(boxes.index(True))


ans = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1], [0, 1, 2]]
(n, x) = (int(input()), int(input()))
print(ans[n % 6][x])


n = int(input())
x = int(input())
xs = {0: [0, 1, 2], 1: [1, 0, 2], 2: [1, 2, 0], 3: [2, 1, 0], 4: [2, 0, 1], 5: [0, 2, 1]}
print(xs[n % 6][x])


n = int(input())
x = int(input())
b0 = [0, 1, 2, 2, 1, 0]
b1 = [1, 0, 0, 1, 2, 2]
b2 = [2, 2, 1, 0, 0, 1]
n1 = n % 6
if x == int(b0[n1]):
	ans = 0
if x == int(b1[n1]):
	ans = 1
if x == int(b2[n1]):
	ans = 2
print(ans)


__author__ = 'zihaozhu'
from sys import stdin
numMove = int(stdin.readline())
indexBall = int(stdin.readline())
answer = indexBall
balls = [0, 0, 0]
a = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(a[numMove % 6][answer])


n = int(input())
x = int(input())

def Print(x):
	print(x)
	exit()
if n % 3 == 0 and x == 1 or (((n + 5) / 6 == (n + 5) // 6 or (n - 1 + 5) / 6 == (n - 1 + 5) // 6) and x == 0) or (((n + 2) / 6 == (n + 2) // 6 or (n - 1 + 2) / 6 == (n - 1 + 2) // 6) and x == 2):
	Print(1)
if (n + 2) / 3 == (n + 2) // 3 and x == 1 or (((n + 4) / 6 == (n + 4) // 6 or (n - 1 + 4) / 6 == (n - 1 + 4) // 6) and x == 2) or (((n + 1) / 6 == (n + 1) // 6 or (n - 1 + 1) / 6 == (n - 1 + 1) // 6) and x == 0):
	Print(0)
Print(2)


import math, sys

def main():
	n = int(input())
	x = int(input())
	d0 = [0, 1, 2, 2, 1, 0]
	d1 = [1, 0, 0, 1, 2, 2]
	d2 = [2, 2, 1, 0, 0, 1]
	if d0[n % 6] == x:
		print(0)
	elif d1[n % 6] == x:
		print(1)
	else:
		print(2)
main()


import sys
import math
import bisect

def main():
	n = int(input())
	m = int(input())
	n %= 6
	A = [0, 1, 2]
	for i in range(n):
		if i % 2 == 0:
			(A[0], A[1]) = (A[1], A[0])
		else:
			(A[1], A[2]) = (A[2], A[1])
	print(A[m])
main()


n = int(input())
x = int(input())
n %= 6
moves = [-1, 0, 1, 1, 0, -1] * 2
pos = [2, 0, 4]
for i in range(3):
	y = (i + sum(moves[pos[i]:pos[i] + n])) % 3
	if y == x:
		print(i)
		break


n = int(input())
l = [0, 0, 0]
b = int(input())
l[b] = 1
i = n % 6
while i >= 1:
	if i % 2 == 0:
		t = l[1]
		l[1] = l[2]
		l[2] = t
	else:
		t = l[1]
		l[1] = l[0]
		l[0] = t
	i = i - 1
print(l.index(1))


n = int(input())
x = int(input())
l = [0, 1, 2]
if n % 6 != 0:
	st = n % 6
else:
	st = 6
for i in range(st):
	if i % 2 == 0:
		(l[0], l[1]) = (l[1], l[0])
	else:
		(l[1], l[2]) = (l[2], l[1])
print(l[x])


n = int(input())
m = int(input())
n = n % 6
o = 0
for i in range(n):
	if i % 2 == 1:
		if o != 0:
			o = 3 - o
	elif o != 2:
		o = 1 - o
if o == m:
	print(0)
else:
	o = 1
	for i in range(n):
		if i % 2 == 1:
			if o != 0:
				o = 3 - o
		elif o != 2:
			o = 1 - o
	if o == m:
		print(1)
	else:
		print(2)


n = int(input())
x = int(input())
n = n % 6
pr = [[0, 1, 1, 2, 2, 0], [1, 0, 2, 1, 0, 2], [2, 2, 0, 0, 1, 1]]
print(pr[x][n])


n = int(input())
x = int(input())
possibleCombinations = ['012', '102', '120', '210', '201', '021']
y = n % 6
print(possibleCombinations[y][x])


def read(type=int):
	return type(input())

def read_arr(type=int):
	return [type(token) for token in input().split()]
n = read()
x = read()
n %= 6
A = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(A[n][x])


n = int(input())
c = int(input())
n = n % 6
if n == 0:
	n = 6
a = [[1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1], [0, 1, 2]]
b = [0, 1, 2]
print(b.index(a[n - 1][c]))


t = int(input())
a = int(input())
s = [0, 1, 2]
t = t % 6
for i in range(1, t + 1):
	if i % 2 == 0:
		(s[1], s[2]) = (s[2], s[1])
	else:
		(s[0], s[1]) = (s[1], s[0])
print(s[a])


n = int(input())
x = int(input())
shells = [0, 0, 0]
shells[x] = 1
if x == 0:
	n = n % 6
if x == 1:
	n = n % 3
if x == 2:
	n = n % 6
for i in range(n, 0, -1):
	if i % 2 == 0:
		(shells[1], shells[2]) = (shells[2], shells[1])
	if i % 2 == 1:
		(shells[0], shells[1]) = (shells[1], shells[0])
if shells[0]:
	print(0)
if shells[1]:
	print(1)
if shells[2]:
	print(2)


import sys
n = int(input())
x = int(input())
ind = [0] * 3
ind[x] = 1
n = n % 6
while n > 0:
	if n % 2 == 1:
		(ind[0], ind[1]) = (ind[1], ind[0])
	else:
		(ind[2], ind[1]) = (ind[1], ind[2])
	n -= 1
for i in range(3):
	if ind[i] == 1:
		print(i)
		sys.exit()


n = int(input())
x = int(input())
l = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
k = n % 6
print(l[k][x])


refer = ((1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1), (0, 1, 2))
n = int(input())
x = int(input())
print(refer[n % 6 - 1][x])


n = int(input())
x = int(input())
t = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = n % 6
print(t[n][x])


def main():
	(n, x) = (int(input()), int(input()))
	seq = [(0, 1, 2)]
	for i in range(6):
		prv = seq[-1]
		cur = (prv[1], prv[0], prv[2]) if i % 2 == 0 else (prv[0], prv[2], prv[1])
		seq.append(cur)
	ans = seq[n % 6][x]
	print(ans)
main()


list = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(list[int(input()) % 6][int(input())])


n = int(input())
x = int(input())
if x == 0:
	if n % 2 == 0:
		n -= 1
	print([0, 1, 2, 2, 1, 0][n % 6])
if x == 2:
	if n % 2:
		n -= 1
	print([2, 1, 0, 0, 1, 2][n % 6])
if x == 1:
	gg = n % 6
	if gg % 2:
		print(['NOPE', 0, 0, 1, 2, 2][gg])
	else:
		print([1, 2, 2, 1, 0, 0][gg])


ls = [0, 1, 2]
(n, x) = (int(input()), int(input()))
for j in range(1, n % 6 + 1):
	if j % 2 != 0:
		(ls[0], ls[1]) = (ls[1], ls[0])
	else:
		(ls[1], ls[2]) = (ls[2], ls[1])
print(ls[x])


def main():
	n = int(input())
	k = int(input())
	n %= 6
	a = [0, 1, 2]
	for i in range(1, n + 1):
		if i % 2 == 1:
			(a[0], a[1]) = (a[1], a[0])
		else:
			(a[1], a[2]) = (a[2], a[1])
	print(a[k])
main()


import sys
inf = float('inf')
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
n = n % 6
k = int(input())
result = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(result[n][k])


def main():
	n = int(input())
	x = int(input())
	states = [(0, 1, 2), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1)]
	print(states[n % 6][x])
main()


n = int(input())
x = int(input())
(ans0, ans1, ans2) = ([0, 1, 2, 2, 1, 0], [1, 0, 0, 1, 2, 2], [2, 2, 1, 0, 0, 1])
mod = n % 6
if ans0[mod] == x:
	print(0)
elif ans1[mod] == x:
	print(1)
else:
	print(2)


a = [1, 2, 2, 1, 0, 0]
b = [0, 0, 1, 2, 2, 1]
c = [2, 1, 0, 0, 1, 2]
n = int(input())
n = n % 6
if not n:
	n = 6
x = int(input())
if a[n - 1] == x:
	print(0)
elif b[n - 1] == x:
	print(1)
else:
	print(2)


actions = int(input())
pos = int(input())
kek = actions % 6
naps = [0, 0, 0]
naps[pos] = 1
while kek > 0:
	if kek % 2 == 0:
		(naps[1], naps[2]) = (naps[2], naps[1])
	else:
		(naps[0], naps[1]) = (naps[1], naps[0])
	kek -= 1
for i in range(0, 3):
	if naps[i] == 1:
		print(i)


a = ['012', '102', '120', '210', '201', '021']
n = int(input()) % 6
p = int(input())
s = a[n]
print(s[p])


def Main():
	n = int(input())
	x = int(input())
	arr = [[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2], [1, 3, 2]]
	print(arr[n % 6][x] - 1)
Main()


n = int(input())
f = int(input())
n %= 6
initial = [0, 1, 2]
k = 0
for _ in range(n):
	(initial[k], initial[k + 1]) = (initial[k + 1], initial[k])
	k = (k + 1) % 2
print(initial[f])


import sys
import math
import collections
from pprint import pprint as pp
mod = 1000000007

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat
(n, x) = (int(input()), int(input()))
n %= 6
while n > 0:
	if n % 2 == 0:
		if x == 2:
			x = 1
		elif x == 1:
			x = 2
	elif x == 0:
		x = 1
	elif x == 1:
		x = 0
	n -= 1
print(x)


n = int(input()) % 6
final = int(input())
while n > 0:
	if n % 2 == 0:
		if final == 2:
			final = 1
		elif final == 1:
			final = 2
	elif final == 0:
		final = 1
	elif final == 1:
		final = 0
	n -= 1
print(final)


n = int(input())
x = int(input())

def t0(n, x):
	l = [0, 1, 2, 2, 1, 0]
	return l[n % 6] == x

def t1(n, x):
	l = [1, 0, 0, 1, 2, 2]
	return l[n % 6] == x

def t2(n, x):
	l = [2, 2, 1, 0, 0, 1]
	return l[n % 6] == x
if t0(n, x):
	print(0)
elif t1(n, x):
	print(1)
elif t2(n, x):
	print(2)


def nap(y):
	if y == 0:
		p = [0, 1, 2]
		return p
	if y == 1:
		p = [1, 0, 2]
		return p
	if y == 2:
		p = [1, 2, 0]
		return p
	if y == 3:
		p = [2, 1, 0]
		return p
	if y == 4:
		p = [2, 0, 1]
		return p
	if y == 5:
		p = [0, 2, 1]
		return p
n = int(input())
x = int(input())
n = n % 6
m = nap(n)
print(m[x])


a = [[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2], [1, 3, 2]]
n = int(input())
x = int(input())
print(a[n % 6][x] - 1)


import math
n = int(input())
x = int(input())
n %= 6
a = [0, 0, 0]
a[x] = 1
while n:
	if n % 2:
		p = a[0]
		a[0] = a[1]
		a[1] = p
	else:
		p = a[2]
		a[2] = a[1]
		a[1] = p
	n -= 1
for i in range(len(a)):
	if a[i]:
		print(i)


ans = ((0, 1, 2), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1))
n = input()
x = input()
a = int(n)
b = int(x)
a = a % 6
print(ans[a][b])


l = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(l[int(input()) % 6][int(input())])


positions = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = int(input())
x = int(input())
k = n % 6
print(positions[k][x])


a = int(input())
b = int(input())
a %= 6
f = [[0, 1, 2], [1, 0, 2], [2, 0, 1], [2, 1, 0], [1, 2, 0], [0, 2, 1]]
print(f[a].index(b))


n = int(input())
x = int(input())
a = [0, 1, 2]

def swap(t1, t2):
	return (t2, t1)
n %= 6
for i in range(n):
	if i % 2 == 0:
		(a[0], a[1]) = swap(a[0], a[1])
	else:
		(a[1], a[2]) = swap(a[1], a[2])
print(a[x])


class CodeforcesTask777ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.x = 0

	def read_input(self):
		self.n = int(input())
		self.x = int(input())

	def process_task(self):
		real_turn = self.n % 6
		moves = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
		self.result = str(moves[real_turn][self.x])

	def get_result(self):
		return self.result
Solution = CodeforcesTask777ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
x = int(input())
lst = [[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2], [1, 3, 2]]
n %= 6
print(lst[n][x] - 1)


from sys import stdin
lines = stdin.readlines()
n = int(lines[0])
m = int(lines[1])
if n > 100:
	n -= (n - 100) // 6 * 6
for i in reversed(range(n)):
	if (i + 1) % 2 == 0:
		if m == 2:
			m = 1
		elif m == 1:
			m = 2
	elif m == 0:
		m = 1
	elif m == 1:
		m = 0
print(m)


print('012102120210201021'[int(input()) % 6 * 3 + int(input())])


n = int(input())
x = int(input())
n %= 6
while n > 0:
	if n % 2 == 0:
		if x in [1, 2]:
			x = 3 - x
	elif x in [0, 1]:
		x = 1 - x
	n -= 1
print(x)


n = int(input())
x = int(input())
a = [1, 2, 3]
if n % 6 == 1:
	a = [2, 1, 3]
if n % 6 == 2:
	a = [2, 3, 1]
if n % 6 == 3:
	a = [3, 2, 1]
if n % 6 == 4:
	a = [3, 1, 2]
if n % 6 == 5:
	a = [1, 3, 2]
print(a[x] - 1)


M = [[None for _ in range(3)] for _ in range(6)]
for p in range(3):
	a = [0, 0, 0]
	a[p] = 1
	for n in range(6):
		M[n][a.index(1)] = p
		k = int(n % 2 == 1)
		(a[k], a[k + 1]) = (a[k + 1], a[k])
n = int(input())
p = int(input())
print(M[n % 6][p])


N = int(input())
N %= 6
x = int(input())
b = [0, 1, 2]
for i in range(N):
	if i % 2 == 0:
		(b[0], b[1]) = (b[1], b[0])
	else:
		(b[1], b[2]) = (b[2], b[1])
print(b[x])


n = int(input())
x = int(input())
n %= 6
a = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
c = a[n][x]
print(c)


n = int(input())
x = int(input())
shell = [0, 0, 0]
shell[x] = 1
n = n % 6
while n > 0:
	if n % 2 == 1:
		temp = shell[0]
		shell[0] = shell[1]
		shell[1] = temp
	else:
		temp = shell[1]
		shell[1] = shell[2]
		shell[2] = temp
	n -= 1
i = 0
while i < 3:
	if shell[i] == 1:
		print(i)
		break
	i += 1


import sys
import math
import time

def main():
	lines = list(map(str.strip, sys.stdin.readlines()))
	indices = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
	n = int(lines[0])
	x = int(lines[1])
	print(indices[n % 6][x])
main()


n = int(input())
x = int(input())
n %= 6
(a, b, c) = (x == 0, x == 1, x == 2)
for i in reversed(list(range(n))):
	if i % 2 == 0:
		(a, b) = (b, a)
	else:
		(b, c) = (c, b)
if a:
	print(0)
elif b:
	print(1)
else:
	print(2)


def main():
	n = int(input())
	x = int(input())
	patterns = [[0, 1, 2, 2, 1, 0], [1, 0, 0, 1, 2, 2], [2, 2, 1, 0, 0, 1]]
	n %= 6
	for (i, pattern) in enumerate(patterns):
		if pattern[n] == x:
			print(i)
main()


n = int(input())
x = int(input())
lst = ['012', '102', '120', '210', '201', '021']
n %= 6
str = lst[n]
print(str[x])


def ri():
	return map(int, input().split())
n = int(input())
x = int(input())
a = [(0, 0, 0), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1), (0, 1, 2)]
n = (n - 1) % 6 + 1
print(a[n][x])


def ginp():
	return map(int, input().split())
n = int(input()) % 6
x = int(input())
m = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
print(m[n][x])


import sys
import math
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def Solution(n, x):
	n = n % 6
	pos = []
	for p in range(3):
		if p == x:
			pos.append('x')
		else:
			pos.append('-')
	for i in range(n, 0, -1):
		if i % 2 == 0:
			tmp = pos[1]
			pos[1] = pos[2]
			pos[2] = tmp
		else:
			tmp = pos[1]
			pos[1] = pos[0]
			pos[0] = tmp
	for pj in range(3):
		if pos[pj] == 'x':
			print(pj)
			return

def main():
	n = int(input())
	x = int(input())
	Solution(n, x)
main()


n = int(input())
n = n % 6
pos = int(input())
arr = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
if pos == 0:
	print(arr[n][pos])
elif pos == 1:
	print(arr[n][pos])
else:
	print(arr[n][pos])


n = int(input())
x = int(input())
d = {0: [1, 2, 2, 1, 0, 0], 1: [1, 0, 0, 1, 2, 2]}
if x == 0:
	if n & 1:
		w = n % 6 - 1
		print(d[0][w])
	elif n == 1:
		print(x)
	else:
		n -= 1
		w = n % 6 - 1
		print(d[0][w])
elif x == 1:
	if n & 1:
		if n == 1 or n == 2:
			print(0)
		else:
			n -= 2
			w = n % 6 - 1
			print(d[0][w])
	elif n == 1 or n == 2:
		print(2)
	else:
		n -= 2
		w = n % 6 - 1
		print(d[1][w])
elif x == 2:
	if n & 1:
		if n == 1:
			print(x)
		else:
			n -= 1
			w = n % 6 - 1
			print(d[1][w])
	else:
		w = n % 6 - 1
		print(d[1][w])


n = int(input())
m = int(input())
h = n % 6
a = [2, 1, 1, 2, 3, 3]
b = [1, 2, 3, 3, 2, 1]
c = [3, 3, 2, 1, 1, 2]
if a[h] == m + 1:
	print('1')
elif b[h] == m + 1:
	print('0')
else:
	print('2')


def comb(n):
	if n == 1:
		return [0, 1, 2]
	elif n == 2:
		return [1, 0, 2]
	elif n == 3:
		return [1, 2, 0]
	elif n == 4:
		return [2, 1, 0]
	elif n == 5:
		return [2, 0, 1]
	else:
		return [0, 2, 1]
n = int(input())
x = int(input())
n = n % 6 + 1
c = comb(n)
print(c[x])


def solve():
	shells = [False] * 3
	n = int(input())
	x = int(input())
	shells[x] = True
	n %= 6
	for i in range(n, 0, -1):
		if i % 2:
			(shells[0], shells[1]) = (shells[1], shells[0])
		else:
			(shells[1], shells[2]) = (shells[2], shells[1])
	for i in range(3):
		if shells[i]:
			print(i)
			return None
solve()


n = int(input())
k = int(input())
n %= 6
d = [[0, 1, 1, 2, 2, 0], [1, 0, 2, 1, 0, 2], [2, 2, 0, 0, 1, 1]]
print(d[k][n])


n = int(input())
i = int(input())
if n == 0:
	print(i)
	exit(0)
n %= 6
a = 0
if i == 0:
	if n == 1:
		a = 1
	elif n == 2:
		a = 1
	elif n == 3:
		a = 2
	elif n == 4:
		a = 2
	else:
		a = 0
elif i == 1:
	if n == 1:
		a = 0
	elif n == 2:
		a = 2
	elif n == 3:
		a = 1
	elif n == 4:
		a = 0
	elif n == 5:
		a = 2
	else:
		a = 1
elif n == 1:
	a = 2
elif n == 2:
	a = 0
elif n == 3:
	a = 0
elif n == 4:
	a = 1
elif n == 5:
	a = 1
else:
	a = 2
print(a)


n = int(input())
s = int(input())
m = [(0, 1, 2), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1)]
print(m[n % 6][s])


n = int(input())
x = int(input())
n %= 6
t = n
a = [0] * 3
a[x] = 1
for i in range(6 - n):
	if (i + t) % 2 == 0:
		(a[0], a[1]) = (a[1], a[0])
	else:
		(a[1], a[2]) = (a[2], a[1])
print(a.index(1))


from sys import maxsize, stdout, stdin, stderr
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
S = lambda : stdin.readline().replace('\n', '').strip()

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
from itertools import permutations
n = I()
x = I()
arr = ['012', '102', '120', '210', '201', '021']
print(arr[n % 6][x])


import sys
fin = sys.stdin
fout = sys.stdout
n = int(fin.readline())
x = int(fin.readline())
if x == 0:
	n %= 6
	ans = [0, 1, 1, 2, 2, 0]
	fout.write(str(ans[n]))
elif x == 1:
	n %= 3
	ans = [1, 0, 2]
	fout.write(str(ans[n]))
elif x == 2:
	n %= 6
	ans = [2, 2, 0, 0, 1, 1]
	fout.write(str(ans[n]))


turns = int(input())
end_pos = int(input())
if end_pos == 0 and (turns % 6 == 5 or turns % 6 == 0):
	print(0)
if end_pos == 0 and (turns % 6 == 1 or turns % 6 == 2):
	print(1)
if end_pos == 0 and (turns % 6 == 3 or turns % 6 == 4):
	print(2)
if end_pos == 1 and (turns % 6 == 1 or turns % 6 == 4):
	print(0)
if end_pos == 1 and (turns % 6 == 3 or turns % 6 == 0):
	print(1)
if end_pos == 1 and (turns % 6 == 2 or turns % 6 == 5):
	print(2)
if end_pos == 2 and (turns % 6 == 2 or turns % 6 == 3):
	print(0)
if end_pos == 2 and (turns % 6 == 4 or turns % 6 == 5):
	print(1)
if end_pos == 2 and (turns % 6 == 1 or turns % 6 == 0):
	print(2)


n = int(input())
final = int(input())
a = []
a.append([0, 1, 2])
a.append([1, 0, 2])
a.append([1, 2, 0])
a.append([2, 1, 0])
a.append([2, 0, 1])
a.append([0, 2, 1])
n %= 6
print(a[n][final])


steps = int(input()) % 6
winner = int(input())
shells = [0] * 3
shells[winner] = 1
for i in reversed(range(steps)):
	step = i + 1
	if step % 2 == 0:
		a = shells[2]
		b = shells[1]
		shells[2] = b
		shells[1] = a
	else:
		a = shells[0]
		b = shells[1]
		shells[0] = b
		shells[1] = a
print(shells.index(1))


I = lambda : list(map(int, input().split()))
n = int(input())
x = int(input())
n -= n // 6 * 6
w = [i == x for i in [0, 1, 2]]
for i in range(n, 0, -1):
	if i % 2:
		w = [w[1], w[0], w[2]]
	else:
		w = [w[0], w[2], w[1]]
print(w.index(True))


a1 = '102'
a2 = '120'
a3 = '210'
a4 = '201'
a5 = '021'
n = int(input())
x = int(input())
if n % 6 == 1:
	print(a1[x])
elif n % 6 == 2:
	print(a2[x])
elif n % 6 == 3:
	print(a3[x])
elif n % 6 == 4:
	print(a4[x])
elif n % 6 == 5:
	print(a5[x])
else:
	print(x)


arr = ['012', '102', '120', '210', '201', '021']
n = int(input())
m = int(input())
n = n % len(arr)
print(arr[n][m])


ans = [[0, 1, 2, 2, 1, 0], [1, 0, 0, 1, 2, 2], [2, 2, 1, 0, 0, 1]]
n = int(input())
n %= 6
x = int(input())
for i in range(3):
	if ans[i][n] == x:
		print(i)
		exit(0)


n = int(input())
x = int(input())
l = [0, 1, 2]
if n % 6 == 1:
	l1 = [1, 0, 2]
elif n % 6 == 2:
	l1 = [1, 2, 0]
elif n % 6 == 3:
	l1 = [2, 1, 0]
elif n % 6 == 4:
	l1 = [2, 0, 1]
elif n % 6 == 5:
	l1 = [0, 2, 1]
else:
	l1 = [0, 1, 2]
print(l[l1[x]])


n = int(input())
x = int(input())
mod = n % 6
pos = []
for i in range(3):
	pos.append(i)
for i in range(mod):
	if i % 2 == 0:
		temp = pos[0]
		pos[0] = pos[1]
		pos[1] = temp
	else:
		temp = pos[1]
		pos[1] = pos[2]
		pos[2] = temp
print(pos[x])


n = int(input())
x = int(input())
n %= 6
for i in range(n, 0, -1):
	if i % 2 == 0 and (x == 1 or x == 2):
		x = 3 - x
	elif i % 2 == 1 and (x == 1 or x == 0):
		x = 1 - x
print(x)


def main():
	n = int(input())
	x = int(input())
	n = n % 6
	pos = [0, 1, 2]
	for i in range(1, n + 1):
		if i % 2 == 1:
			(pos[0], pos[1]) = (pos[1], pos[0])
		else:
			(pos[1], pos[2]) = (pos[2], pos[1])
	print(pos[x])
main()


n = int(input())
x = int(input())
n %= 6
arr = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1], [0, 1, 2]]
print(arr[n][x])


n = int(input())
x = int(input())
arr = [0, 1, 2]
n %= 6
while n:
	if n % 2:
		(arr[0], arr[1]) = (arr[1], arr[0])
	else:
		(arr[1], arr[2]) = (arr[2], arr[1])
	n -= 1
print(arr.index(x))


n = int(input())
l = int(input())
if l == 0:
	k = 'oxx'
elif l == 1:
	k = 'xox'
else:
	k = 'xxo'
for i in range(n % 6 + 1, 7):
	if i % 2 == 0:
		k = k[0] + k[2] + k[1]
	else:
		k = k[1] + k[0] + k[2]
print(k.find('o'))


n = int(input())
x = int(input())
n = n % 6
l1 = [0, 1, 2, 2, 1, 0]
l2 = [1, 0, 0, 1, 2, 2]
l3 = [2, 2, 1, 0, 0, 1]
if l1[n] == x:
	print(0)
elif l2[n] == x:
	print(1)
else:
	print(2)


l = '122100'
m = '001221'
r = '210012'
n = int(input())
b = input()
n = n % 6 - 1
if l[n] == b:
	print(0)
elif m[n] == b:
	print(1)
elif r[n] == b:
	print(2)


a = int(input())
b = int(input())
l = [0, 1, 2]
l[b] = 5
a = a % 6
for i in range(a, 0, -1):
	if i % 2 == 1:
		if l[2] != 5:
			(l[1], l[0]) = (l[0], l[1])
	elif l[0] != 5:
		(l[1], l[2]) = (l[2], l[1])
print(l.index(5))


n = int(input())
x = int(input())
l1 = [2, 3, 3, 2, 1, 1]
l2 = [1, 1, 2, 3, 3, 2]
l3 = [3, 2, 1, 1, 2, 3]
if l1[n % len(l1) - 1] == x + 1:
	print(0)
elif l2[n % len(l2) - 1] == x + 1:
	print(1)
else:
	print(2)


n = int(input())
x = int(input())
dic0 = {1: 1, 2: 2, 3: 2, 4: 1, 5: 0, 0: 0}
dic1 = {1: 0, 2: 0, 3: 1, 4: 2, 5: 2, 0: 1}
dic2 = {1: 2, 2: 1, 3: 0, 4: 0, 5: 1, 0: 2}
t = n % 6
if dic0[t] == x:
	print(0)
elif dic1[t] == x:
	print(1)
else:
	print(2)


N = int(input())
end = int(input())
left = [1, 2, 3, 3, 2, 1]
middle = [2, 1, 1, 2, 3, 3]
if left[N % 6] - 1 == end:
	print(0)
elif middle[N % 6] - 1 == end:
	print(1)
else:
	print(2)


n = int(input())
x = int(input())
ans = 0
if x == 1:
	if n % 2 != 0:
		x = 0
	else:
		x = 2
	n -= 1
if x == 2:
	if n % 2 == 0:
		p = n // 3
		if p % 2 != 0:
			ans = n % 3
		else:
			ans = 2 - n % 3
	else:
		p = (n - 1) // 3
		if p % 2 != 0:
			ans = (n - 1) % 3
		else:
			ans = 2 - (n - 1) % 3
if x == 0:
	if n % 2 == 0:
		p = (n - 1) // 3
		if p % 2 != 0:
			ans = 2 - (n - 1) % 3
		else:
			ans = (n - 1) % 3
	else:
		p = n // 3
		if p % 2 != 0:
			ans = 2 - n % 3
		else:
			ans = n % 3
print(ans)


def transpose(p, i, j):
	if p != i and p != j:
		return p
	else:
		return i if p == j else j

def cycle(p, n):
	return (p + n) % 3

def f(m, p):
	if m == 0:
		return p
	elif m == 1:
		return transpose(p, 0, 1)
	elif m == 2:
		return cycle(p, 1)
	elif m == 3:
		return transpose(p, 0, 2)
	elif m == 4:
		return cycle(p, 2)
	elif m == 5:
		return transpose(p, 1, 2)
n = int(input())
p = int(input())
m = n % 6
print(f(m, p))


n = int(input())
x = int(input())
n = n % 6
a = [0, 1, 2]
i = 0
for j in range(n):
	(a[i], a[i + 1]) = (a[i + 1], a[i])
	i = (i + 1) % 2
print(a[x])