#include <bits/stdc++.h>
using namespace std;
int N, P, pos[6][3] = {0, 1, 2, 1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1};
int main() {
  scanf("%d%d", &N, &P);
  N %= 6;
  printf("%d", pos[N][P]);
  return 0;
}
