#include <bits/stdc++.h>
using namespace std;
int a[3] = {0};
void sw(int &x, int &y) {
  int b = x;
  x = y, y = b;
}
int main() {
  long long n, x;
  cin >> n >> x;
  a[x] = 1;
  n %= 6;
  if (n == 0) n = 6;
  for (int i = n; i >= 1; i--) {
    if (i & 1)
      sw(a[0], a[1]);
    else
      sw(a[1], a[2]);
  }
  if (a[0]) printf("0\n");
  if (a[1]) printf("1\n");
  if (a[2]) printf("2\n");
  return 0;
}
