#include <bits/stdc++.h>
int main() {
  int a[10][5] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0},
                  {2, 1, 0}, {2, 0, 1}, {0, 2, 1}},
      n, m;
  scanf("%d %d", &n, &m);
  n = n % 6;
  printf("%d\n", a[n][m]);
  return 0;
}
