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·109) — 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.

  1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 
  2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 
  3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 
  4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. 
#include <bits/stdc++.h>
namespace std {
template <typename _Key, typename _Hash = std::hash<_Key>>
using hash_set = std::unordered_set<_Key, _Hash>;
template <typename _Key, typename _Hash = std::hash<_Key>>
using hash_mset = std::unordered_multiset<_Key, _Hash>;
template <typename _Key, typename _Val, typename _Hash = std::hash<_Key>>
using hash_map = std::unordered_map<_Key, _Val, _Hash>;
template <typename _Key, typename _Hash = std::hash<_Key>>
using hash_mmap = std::unordered_multimap<_Key, _Hash>;
template <typename _Key, typename _Cmp = std::less<_Key>>
using mset = std::multiset<_Key, _Cmp>;
template <typename _Key, typename _Val, typename _Cmp = std::less<_Key>>
using mmap = std::multimap<_Key, _Val, _Cmp>;
template <typename _Key>
using rset = std::set<_Key, std::greater<_Key>>;
template <typename _Key>
using rmset = std::multiset<_Key, std::greater<_Key>>;
template <typename _Key, typename _Val>
using rmap = std::map<_Key, std::greater<_Key>>;
template <typename _Key, typename _Val>
using rmmap = std::multimap<_Key, _Val, std::greater<_Key>>;
static std::ostream& fdeb = cerr;
struct NullOstream {};
template <typename T>
NullOstream& operator<<(NullOstream& out, const T&) {
  return out;
}
NullOstream& operator<<(NullOstream& out, std::ostream& (*)(std::ostream&)) {
  return out;
}
static NullOstream deb;
static NullOstream debl;
template <int _Ind, typename... _Args>
struct __TuplePrinter {
  static void print(ostream& out, const tuple<_Args...>& t) {
    __TuplePrinter<_Ind - 1, _Args...>::print(out, t);
    out << ' ' << get<_Ind>(t);
  }
};
template <typename... _Args>
struct __TuplePrinter<0, _Args...> {
  static void print(ostream& out, const tuple<_Args...>& t) {
    out << '(' << get<0>(t);
  }
};
template <typename... _Args>
ostream& operator<<(ostream& out, const tuple<_Args...>& t) {
  __TuplePrinter<sizeof...(_Args) - 1, _Args...>::print(out, t);
  out << ')';
  return out;
}
template <typename _T1, typename _T2>
ostream& operator<<(ostream& out, const pair<_T1, _T2>& p) {
  return out << '(' << p.first << ' ' << p.second << ')';
}
using uchar = unsigned char;
using ushort = unsigned short;
using uint = unsigned int;
using lld = long long;
using ulld = unsigned long long;
static const int MOD = 1e9 + 7;
static const int INF = MOD;
static const lld HASHP = 37;
}  // namespace std
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  N = (N - 1) % 6 + 1;
  static const std::vector<int> kMoves{0, 2, 1, -1, 1, 0, 2, -1};
  unsigned MOVE_MASK = 0x4;
  int initial_state = K | (MOVE_MASK * (N % 2));
  int state = initial_state;
  int num_turns = 0;
  do {
    state = kMoves[state] | (state & MOVE_MASK ? 0 : MOVE_MASK);
    ++num_turns;
    deb << state;
  } while (num_turns < N);
  std::cout << (state & ~MOVE_MASK) << std::endl;
  return 0;
}
