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

Solutions:
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)


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)


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])


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')


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()


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])


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)


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])


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())
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())


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)


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()


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)


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])