#include <bits/stdc++.h>
using namespace std;
int fk[3];
int main() {
  int n, m;
  memset(fk, 0, sizeof(fk));
  scanf("%d%d", &n, &m);
  fk[m] = 1;
  while (n % 6) {
    if (n & 1)
      swap(fk[0], fk[1]);
    else
      swap(fk[1], fk[2]);
    --n;
  }
  for (int i = 0; i < 3; ++i)
    if (fk[i]) {
      printf("%d", i);
      break;
    }
  return 0;
}
