#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  n %= 6;
  vector<int> kek = {0, 1, 2};
  for (int i = 0; i < n; ++i) {
    if (i & 1)
      swap(kek[1], kek[2]);
    else
      swap(kek[0], kek[1]);
  }
  cout << kek[x];
  return 0;
}
