#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void upmax(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void upmin(T& a, T b) {
  if (a > b) a = b;
}
const int maxn = 100007;
const int maxm = 200007;
const int mod = 1000000007;
const int inf = 0x7fffffff;
const double eps = 1e-7;
typedef int arr[maxn];
typedef int adj[maxm];
inline int fcmp(double a, double b) {
  if (fabs(a - b) <= eps) return 0;
  if (a < b - eps) return -1;
  return 1;
}
inline int add(int a, int b) { return ((long long)a + b) % mod; }
inline int mul(int a, int b) { return ((long long)a * b) % mod; }
inline int dec(int a, int b) { return add(a, mod - b % mod); }
inline int Pow(int a, int b) {
  int t = 1;
  while (b) {
    if (b & 1) t = mul(t, a);
    a = mul(a, a), b >>= 1;
  }
  return t;
}
template <typename Type>
inline Type RD() {
  Type x = 0;
  int flag = 0;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  (c == '-') ? (flag = 1) : (x = c - '0');
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  return flag ? -x : x;
}
inline char rdch() {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  return c;
}
int n, x;
int step[2][3];
void input() {
  n = RD<int>();
  n %= 6;
  x = RD<int>();
}
void solve() {
  step[0][1] = 2;
  step[0][2] = 1;
  step[1][0] = 1;
  step[1][1] = 0;
  step[1][2] = 2;
  for (int i = n, _ = 1; i >= _; i--) x = step[i & 1][x];
  printf("%d\n", x);
}
int main() {
  input();
  solve();
  return 0;
}
