Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

A. Shell Game

time limit per test

0.5 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputBomboslav 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.

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/23/2017 21:05:35 (c4).

Desktop version, switch to mobile version.
User lists

Name |
---|