#include <bits/stdc++.h>
int main() {
  int n, x;
  int i;
  int a[3][6] = {{1, 1, 2, 2, 0, 0}, {0, 2, 1, 0, 2, 1}, {2, 0, 0, 1, 1, 2}};
  while (scanf("%d%d", &n, &x) != EOF) {
    if (n % 6 == 0)
      printf("%d\n", a[x][5]);
    else
      printf("%d\n", a[x][n % 6 - 1]);
  }
  return 0;
}
