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