#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0, j = 0, n, a;
  cin >> n >> a;
  i = n % 6;
  if ((i == 1 || i == 0) && a == 2)
    cout << "2";
  else if ((i == 2 || i == 5) && a == 1)
    cout << "2";
  else if ((i == 3 || i == 4) && a == 0)
    cout << "2";
  else if ((i == 1 || i == 4) && a == 1)
    cout << "0";
  else if ((i == 2 || i == 3) && a == 2)
    cout << "0";
  else if ((i == 5 || i == 0) && a == 0)
    cout << "0";
  else if ((i == 1 || i == 2) && a == 0)
    cout << "1";
  else if ((i == 3 || i == 0) && a == 1)
    cout << "1";
  else if ((i == 4 || i == 5) && a == 2)
    cout << "1";
  return 0;
}
