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