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