#include <bits/stdc++.h>
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  if (x == 0) {
    if (n % 6 == 1 || n % 6 == 2)
      printf("1\n");
    else if (n % 6 == 3 || n % 6 == 4)
      printf("2\n");
    else if (n % 6 == 5 || n % 6 == 0)
      printf("0\n");
  } else if (x == 1) {
    if (n % 3 == 1)
      printf("0\n");
    else if (n % 3 == 2)
      printf("2\n");
    else if (n % 3 == 0)
      printf("1\n");
  } else if (x == 2) {
    if (n % 6 == 0 || n % 6 == 1)
      printf("2\n");
    else if (n % 6 == 2 || n % 6 == 3)
      printf("0\n");
    else if (n % 6 == 4 || n % 6 == 5)
      printf("1\n");
  }
  return 0;
}
